필터 지우기
필터 지우기

How to incorporate a .m file into a while loop

조회 수: 1 (최근 30일)
Brady Wayne Robinson
Brady Wayne Robinson 2018년 9월 20일
편집: Wycliff Dembe 2018년 9월 21일
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.

답변 (1개)

Wycliff Dembe
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.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by