How to incorporate a .m file into a while loop
1 回表示 (過去 30 日間)
古いコメントを表示
I have a .m file that is given and I need to write a while loop the incorporates this .m file to find when that function equals a certain number. This is the specific question There is a file called muller.m. It solves an off-road vehicle problem. Given an input of a vehicle’s length in inches, it computes a maximum angle that the vehicle can navigate without hitting its nose into the ground. I would like to be certain that the vehicle I’m designing can clear a 35◦ angle. How short must the vehicle be? Do this with a while loop that starts at 95 inches and decreases by 0.1 inch until the right length is discovered.
0 件のコメント
回答 (1 件)
Wycliff Dembe
2018 年 9 月 21 日
編集済み: Wycliff Dembe
2018 年 9 月 21 日
I'm assuming your function muller.m is of the form:
function any_angle = muller(any_length)
%%calculate angle from length
% eg. any_angle = any_length/2;
end
Then you can calculate your length by calling your function muller and using your while loop as follows:
your_angle = 35; % o
current_length = 95; % starting length
ressolution = 0.1; % what you want to keep reducing from length
current_angle = muller(current_length); % initial angle calculated from maximum height = 95 inch
while current_angle > your_angle
current_length = current_length - ressolution; % decrease length
current_angle = muller(current_length);
end
your_final_length = current_length; %the length you need that produces your_angle
Remember, you might need to change the "greater than" sign (>) on the while loop to "less than" sign (<) depending on how your muller function converts length to angle.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!