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

1 view (last 30 days)
Abdulaziz Abutunis on 28 Feb 2016
Commented: Walter Roberson on 28 Feb 2016
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 CommentsShowHide 1 older comment
Abdulaziz Abutunis on 28 Feb 2016
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

Walter Roberson on 28 Feb 2016
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 CommentsShowHide 1 older comment
Walter Roberson on 28 Feb 2016
In R2014a on OS-X I get a curve for all three versions. Which MATLAB version are you using?