Plotting multiple graphs on the same plot

2 Ansichten (letzte 30 Tage)
Amy Topaz
Amy Topaz am 24 Mär. 2022
Kommentiert: KSSV am 24 Mär. 2022
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?

Antworten (1)

KSSV
KSSV am 24 Mär. 2022
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 Kommentare
Amy Topaz
Amy Topaz am 24 Mär. 2022
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 am 24 Mär. 2022
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')

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by