Iterating to Find the max value

1 次查看(过去 30 天)
Stephen Trainor
Stephen Trainor 2011-11-21
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

回答(3 个)

Andrei Bobrov
Andrei Bobrov 2011-11-21
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 2011-11-21
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 个评论
Stephen Trainor
Stephen Trainor 2011-11-21
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 2011-11-21
@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.

请先登录,再进行评论。


Daniel Shub
Daniel Shub 2011-11-21
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!

Translated by