Iterating to Find the max value

1 view (last 30 days)
Stephen Trainor
Stephen Trainor on 21 Nov 2011
Hi, I am trying to find the maximum value of "Fm" that can be outputted from the programme. The programme is iterating from 1 through 359 degrees for that formula.
I know that i can just output all of the numbers and physically find which one is largest, but is there some sort of "if" statement I can make that will find it for me automatically?
Here is my code:
maxangle=359;
for muscleangle=1:maxangle;
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm=Fmy/sind(muscleangle);
Fmx=Fm*cosd(muscleangle);
disp (Fm);
disp(muscleangle);
end
I would really appreciate any help.
Thanks

Answers (3)

Andrei Bobrov
Andrei Bobrov on 21 Nov 2011
muscleangle = 1:360;
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm=Fmy./sind(muscleangle);
Fmx=Fm.*cosd(muscleangle);
out = max(Fm(isfinite(Fm)))

Jan
Jan on 21 Nov 2011
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm_max = -Inf;
for muscleangle=1:359
Fm = Fmy / sind(muscleangle);
Fmx = Fm * cosd(muscleangle);
if Fm > Fm_max % Or Fmx? [EDITED: FM_max->Fm_max]
Fm_max = Fm;
disp(Fm);
disp(muscleangle);
end
end
  2 Comments
Stephen Trainor
Stephen Trainor on 21 Nov 2011
Thank you very much for the quick reply, however I am still getting the following error:
??? Undefined function or variable 'FM_max'.
Error in ==> armraise at 12
if Fm > FM_max % Or Fmx?
Also, will this code give me my largest answer for Fm?
Jan
Jan on 21 Nov 2011
@Stephen: This is a typo obviously. I think, it would not be to hard to find out, that I've written "Fm_max" at first and "FM_max" afterwards. But both need the same name.
I've interpreted "just output all of the numbers and physically find which one is largest" such that you know how to solve this using MAX already. Therefore I've posted the less efficient loop method using IF.

Sign in to comment.


Daniel Shub
Daniel Shub on 21 Nov 2011
a=0.15;
b=0.3;
c=0.6;
W=40;
Wo=60;
Fmy=(b*W+c*Wo)/a;
Fm_max = -Inf;
muscleangle=1:359;
Fm = Fmy./sind(muscleangle);
Fmx = Fm.*cosd(muscleangle);
Fm_max = max(Fm)

Community Treasure Hunt

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

Start Hunting!