필터 지우기
필터 지우기

why ezplot(f,[3000,4000]) would not work

조회 수: 1 (최근 30일)
Abdulaziz Abutunis
Abdulaziz Abutunis 2016년 2월 28일
댓글: Walter Roberson 2016년 2월 28일
Hi all,
I have this next function which is the result of solving for Px in my code
f=@(Px) (16*(-(((27*Px)/2 - 65625)*((27*Px)/2 + 65625))/4)^(1/2))/27;
the problem is that when I use the ezplot(f,[3000,5000]) it will plot wrong plot. However, if I use
ezplot((16*(-(((27*Px)/2 - 65625)*((27*Px)/2 + 65625))/4)^(1/2))/27,[3000,5000])
the curve will be correct. Please if you have any suggestion to solve this issue advise me.
Thanks
Aziz
  댓글 수: 2
John D'Errico
John D'Errico 2016년 2월 28일
No. Actually, the result that you claim does work, will fail in MATLAB.
ezplot((16*(-(((27*Px)/2 - 65625)*((27*Px)/2 + 65625))/4)^(1/2))/27,[3000,5000])
Undefined function or variable 'Px'.
I think you have things confused.
Abdulaziz Abutunis
Abdulaziz Abutunis 2016년 2월 28일
I am sorry I forgot the ' when I posted the function it should be ezplot('(16*(-(((27*Px)/2 - 65625)*((27*Px)/2 + 65625))/4)^(1/2))/27',[3000,5000])
Thank you, Aziz

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 28일
Your second form relies upon whatever Px happens to be in memory, and will fail if Px is not a scalar.
Possibly what you meant to post was
ezplot('(16*(-(((27*Px)/2 - 65625)*((27*Px)/2 + 65625))/4)^(1/2))/27',[3000,5000])
When I try that, the output is identical to plotting with your f anonymous function.
When I use your f anonymous function, ezplot gives a warning about f not being vectorized. You can remove that by vectorizing it:
f=@(Px) (16*(-(((27*Px)/2 - 65625).*((27*Px)/2 + 65625))/4).^(1/2))/27;
The output is the same exactly as for the non-vectorized version, and the same exactly as for the string version.
  댓글 수: 2
Abdulaziz Abutunis
Abdulaziz Abutunis 2016년 2월 28일
Thank you Walter for the quick response. you are right, I forgot to add '...'. As you mentioned, the output for the vectorized and non-vectorized are the same (a straight line), however, the string version gave different curve which is correct when I checked a solved problem.
Thank you, Aziz
Walter Roberson
Walter Roberson 2016년 2월 28일
In R2014a on OS-X I get a curve for all three versions. Which MATLAB version are you using?

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by