Checking multiple values in an equation in MATLAB
Show older comments
For a given value of x, how could you use MATLAB to find what the smallest z value greater than 5 if z=x/y, and y values are considered in increments of 6 (6, 12, 18,...)?
Answers (2)
Walter Roberson
on 10 Sep 2022
z5min = min(z(z > 5))
format long
x = 1271;
[y,z] = result(x)
function [y,z] = result(x)
if x <= 30
disp('Problem not solvable')
y = [];
z = [];
return
end
if mod(x,30)==0
y = x/5 - 6;
else
y = 6*floor(x/30);
end
z = x/y;
end
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!