How to incorporate a .m file into a while loop
    4 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (1)
  Wycliff Dembe
      
 on 21 Sep 2018
        
      Edited: Wycliff Dembe
      
 on 21 Sep 2018
  
      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 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!