Reputation: 141
I want to plot multiple functions according to different values of alpha. My function is: x^3+x+y+(alpha)*y=0
ezplot('x.^3 + x + y + y', [-10 10 -10 10]);
hold on
ezplot('x.^3 + x + y + 2*y', [-10 10 -10 10]);
hold on
ezplot('x.^3 + x + y + 3*y', [-10 10 -10 10]);
hold on
ezplot('x.^3 + x + y + 4*y', [-10 10 -10 10]);
...
When I write the code with for loop which does the same work the code shown above, plot does not show nothing. I do not want to just copy and paste to get 100 functions according to 100 different values of alpha. So in this fashion how can I implement this code with using loops?
Figure shows the four equation which are shown above.
Upvotes: 0
Views: 667
Reputation: 1868
As is stated in the comments MATLAB doesn't recommend the use of ezplot
. If you're using MATLAB R2017b, then you can use fimplicit
. If you don't then you can use both fplot
and plot
as an alternative. Both, however, need an explicit form. The code for the two latter is then:
for fplot
:
for alpha=1:100
y = @(x) -(x.^3+x)/(1+alpha);
fplot(y,[-10 10])
ylim([-10 10])
hold on
end
hold off
for plot
:
x = -10:.1:10;
for alpha=1:100
y = -(x.^3+x)/(1+alpha);
plot(x,y)
ylim([-10 10])
hold on
end
hold off
I don't have MATLAB R2017b myself, so I couldn't test the code, but if you want to use fimplicit
, I think it looks like this:
for alpha=1:100
fimplicit(@(x,y) x.^3 +x + (1+alpha)*y, [-10 10 -10 10])
hold on
end
hold off
Upvotes: 3