필터 지우기
필터 지우기

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)))
  댓글 수: 1
Stephen Trainor
Stephen Trainor 2011년 11월 21일
Thanks a million, thats perfect

댓글을 달려면 로그인하십시오.


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)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by