tw-S
tw-S

Reputation: 1217

Using ezplot with specified ordinate range

I have a symbolic function that I am plotting with ezplot:

  ezplot(f, [0,1]);

I could not find a way to specify the y-values (ordniate) to plot this function. However, I want f to be plotted for x in [0,1] and y in [0,1] also. Default ezplot plots my function for y in [0,20] or something like that. How can I specify the y-range?

Here is my function (in q):

 ((490*q^3 - 1300*q^2 + 1080*q - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (655*q^3 - 1570*q^2 + 1160*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)))/((10*q^2 - 7*q^3)/(480*q - 600*q^2 + 180*q^3) - (1080*q - 1300*q^2 + 490*q^3 - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + (((10*q^2 - 7*q^3)/(480*q - 600*q^2 + 180*q^3) - (1080*q - 1300*q^2 + 490*q^3 - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + ((1080*q - 1300*q^2 + 490*q^3 - 240)*(1160*q - 1570*q^2 + 655*q^3 - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^2 - ((1080*q - 1300*q^2 + 490*q^3 - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (1160*q - 1570*q^2 + 655*q^3 - 240)/(720*q - 900*q^2 + 270*q^3))^3)^(1/2) + ((1080*q - 1300*q^2 + 490*q^3 - 240)*(1160*q - 1570*q^2 + 655*q^3 - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^(1/3) - (490*q^3 - 1300*q^2 + 1080*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)) + ((10*q^2 - 7*q^3)/(2*(90*q^3 - 300*q^2 + 240*q)) - (490*q^3 - 1300*q^2 + 1080*q - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + (((10*q^2 - 7*q^3)/(2*(90*q^3 - 300*q^2 + 240*q)) - (490*q^3 - 1300*q^2 + 1080*q - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + ((490*q^3 - 1300*q^2 + 1080*q - 240)*(655*q^3 - 1570*q^2 + 1160*q - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^2 - ((490*q^3 - 1300*q^2 + 1080*q - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (655*q^3 - 1570*q^2 + 1160*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)))^3)^(1/2) + ((490*q^3 - 1300*q^2 + 1080*q - 240)*(655*q^3 - 1570*q^2 + 1160*q - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^(1/3)

Upvotes: 1

Views: 4420

Answers (2)

marsei
marsei

Reputation: 7751

Your function of q as written in a string can be evaluated using ezplot, but you will have a much better control of the plot properties using the plot function. You can set the Xlim and YLim properties for example.

Here is a piece of code

%evaluate function and plot
f = ' ((490*q^3 - 1300*q^2 + 1080*q - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (655*q^3 - 1570*q^2 + 1160*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)))/((10*q^2 - 7*q^3)/(480*q - 600*q^2 + 180*q^3) - (1080*q - 1300*q^2 + 490*q^3 - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + (((10*q^2 - 7*q^3)/(480*q - 600*q^2 + 180*q^3) - (1080*q - 1300*q^2 + 490*q^3 - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + ((1080*q - 1300*q^2 + 490*q^3 - 240)*(1160*q - 1570*q^2 + 655*q^3 - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^2 - ((1080*q - 1300*q^2 + 490*q^3 - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (1160*q - 1570*q^2 + 655*q^3 - 240)/(720*q - 900*q^2 + 270*q^3))^3)^(1/2) + ((1080*q - 1300*q^2 + 490*q^3 - 240)*(1160*q - 1570*q^2 + 655*q^3 - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^(1/3) - (490*q^3 - 1300*q^2 + 1080*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)) + ((10*q^2 - 7*q^3)/(2*(90*q^3 - 300*q^2 + 240*q)) - (490*q^3 - 1300*q^2 + 1080*q - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + (((10*q^2 - 7*q^3)/(2*(90*q^3 - 300*q^2 + 240*q)) - (490*q^3 - 1300*q^2 + 1080*q - 240)^3/(27*(240*q - 300*q^2 + 90*q^3)^3) + ((490*q^3 - 1300*q^2 + 1080*q - 240)*(655*q^3 - 1570*q^2 + 1160*q - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^2 - ((490*q^3 - 1300*q^2 + 1080*q - 240)^2/(9*(240*q - 300*q^2 + 90*q^3)^2) - (655*q^3 - 1570*q^2 + 1160*q - 240)/(3*(90*q^3 - 300*q^2 + 240*q)))^3)^(1/2) + ((490*q^3 - 1300*q^2 + 1080*q - 240)*(655*q^3 - 1570*q^2 + 1160*q - 240))/(6*(240*q - 300*q^2 + 90*q^3)^2))^(1/3)';
h=ezplot(f,[0 1]);

%get X and Y data
X = get(h,'XData');
Y = get(h,'YData');

%plot X and Y over the ezplot
plot(X,Y)
set(gca, 'XLim', [0 1], 'YLim', [0 2.5]);

Upvotes: 1

Dan
Dan

Reputation: 45752

From the docs:

ezplot(fun2,[xmin,xmax,ymin,ymax])

So I'm guessing in your case it's simply

ezplot(f, [0,1,0,1])

But that assumes f is an implicit function. So you must write it as such. For example writing the explicit function f = @(x) x as an implicit function and plotting it between 0 and 1:

f = @(x,y) y - x;
ezplot(f, [0,1,0,1])

So basically just rewrite it as y - whatever you had before assuming your f was explicit. If it was implicit then you can literally just specify the y-axis limits.

For your example writing the explicit function in your comment as an implicit function:

f = @(x,y) = y - (x^2-x^(3/2)+...)

Upvotes: 1

Related Questions