Plotting multiple graphs on the same plot

1 回表示 (過去 30 日間)
Amy Topaz
Amy Topaz 2022 年 3 月 24 日
コメント済み: KSSV 2022 年 3 月 24 日
I need to plot multiple plots on the same graph for different values of z and indicate the maximum value:
For z = 1, 2, 9, 77
y = sin(8*x+pi) + 2*x^2/3 + z*3
How to do that?

回答 (1 件)

KSSV
KSSV 2022 年 3 月 24 日
x = linspace(0,2*pi) ;
z = [1, 2, 9, 77]' ;
y = sin(8*x+pi) + 2*x.^2/3 + 3*z ;
plot(x,y) ;
legend('z=1','z=2','z=9','z=77')
Read about hold on
  2 件のコメント
Amy Topaz
Amy Topaz 2022 年 3 月 24 日
x = linspace(-4*g,4*g);
y = [0.01*g 0.2*g 0.6*g g];
Hx = (1/pi)*(atan(((g/2 + x)./y) + atan((g/2 - x)./y)));
Hy = (-1/2*pi)*(log((g/2 + x).^2 + (y).^2./(g/2 - x).^2 + (y).^2));
plot(x, Hx, 'g-v', 'LineWidth', 2)
xlabel x1
grid minor
title ('y1 = 0.01*g')
ylabel Hx1
legend('y=0.01g','y = 0.2g','y = 0.6g','y = g')
How to rectify this?
KSSV
KSSV 2022 年 3 月 24 日
You need to transpose y.
x = linspace(-4*g,4*g);
y = [0.01*g 0.2*g 0.6*g g]';
Hx = (1/pi)*(atan(((g/2 + x)./y) + atan((g/2 - x)./y)));
Hy = (-1/2*pi)*(log((g/2 + x).^2 + (y).^2./(g/2 - x).^2 + (y).^2));
plot(x, Hx, '-v', 'LineWidth', 2)
xlabel x1
grid minor
title ('y1 = 0.01*g')
ylabel Hx1
legend('y=0.01g','y = 0.2g','y = 0.6g','y = g')

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by