How to plot an equation with different parameter value?
66 次查看(过去 30 天)
显示 更早的评论
x = 0:0.01:+10;
c = 1;
Y = (1-x.^2).^c;
plot(x,Y); hold on;
c = 1.1;
Y = (1-x.^2).^c;
plot(x,Y); hold on;
c=1.4;
Y = (1-x.^2).^c;
plot(x,Y); hold on;
c=0.3;
Y = (1-x.^2).^c;
plot(x,Y)
I am sure there is a concise way to do this same thing. I want to plot the equation y = (1-x^2)^c for c = [1, 1.1, 1.4, 0.3]. How to achieve that? In general how to plot an equation with varying parameter value chosen from an array?
1 个评论
采纳的回答
Star Strider
2022-1-12
Try this —
x = 0:0.01:+10;
c = [1;1.1;1.4;0.3];
Y = (1-x.^2).^c;
figure
plot(x,Y)
legend(compose('c = %.1f',c), 'Location','best')
With‘c’ a vector, this can be done in one step. The legend is even easier to create!
.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!