How to plot an equation with different parameter value?

8 ビュー (過去 30 日間)
Abdul Muhaymin
Abdul Muhaymin 2022 年 1 月 12 日
回答済み: Star Strider 2022 年 1 月 12 日
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;
Warning: Imaginary parts of complex X and/or Y arguments ignored.
c=1.4;
Y = (1-x.^2).^c;
plot(x,Y); hold on;
Warning: Imaginary parts of complex X and/or Y arguments ignored.
c=0.3;
Y = (1-x.^2).^c;
plot(x,Y)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
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 件のコメント
Torsten
Torsten 2022 年 1 月 12 日
It's correct as you proceed. But for Y to be real, x must be in [-1:1].

サインインしてコメントする。

採用された回答

Star Strider
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)
Warning: Imaginary parts of complex X and/or Y arguments ignored.
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 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by