Problems with my 2D graph

Hello! Can someone help me to make my graph 2 look like number 1 please? I want the Y axis to be the same
1)
2)
Code
e_inf = 11.7 ;
Wp1 = 1.0856e11;
gamma1 = 2.3518e9 ;
Wp2 = 3.4330e11;
gamma2 = 5.6747e9 ;
Wp3 = 1.0856e12;
gamma3 = 8.8952e9 ;
Wp4 = 3.4330e12;
gamma4 = 3.2292e10;
w1 = 1e13;
w2 = 1e10;
w3 = 1e15;
index = 0;
K = w1:w2:w3;
% Loop is not necessary!
e1 = e_inf - ((Wp1^2)./K.^2+1i*K*gamma1);
e2 = e_inf - ((Wp2^2)./K.^2+1i*K*gamma2);
e3 = e_inf - ((Wp3^2)./K.^2+1i*K*gamma3);
e4 = e_inf - ((Wp4^2)./K.^2+1i*K*gamma4);
f=K;
x=f;
figure
y1 = real(e1);
semilogx(x,y1, 'b-','linewidth',2, 'displayName', 'e_1')
hold on
y2 = real(e2);
semilogx(x,y2, 'g-', 'linewidth',2,'displayName', 'e_2'), grid on
y3 = real(e3);
semilogx(x,y3, 'r-', 'linewidth',2,'displayName', 'e_3'), grid on
y4 = real(e4);
semilogx(x,y4, 'black-', 'linewidth',2,'displayName', 'e_4'), grid on
hold off
legend('toggle');
This statement is incomplete.

8 Kommentare

Les Beckham
Les Beckham am 30 Dez. 2022
Bearbeitet: Les Beckham am 30 Dez. 2022
The code you posted (which you should format as code, by the way) creates graph 2.
If you really meant that you want your graph to look like graph 1, then explain what, specifically, you like about graph 1 and want to replicate in your graph. Is it the line styles (dashed vs. solid)? The legend with no box? The blue axes? The two x axes? The actual shape of the lines, of course, will not match because of the data that you are plotting.
BTW - to format your code, edit the question, select all of the code, and press the left hand button in the CODE section of the toolbar above.
Walter Roberson
Walter Roberson am 30 Dez. 2022
The "incomplete" is due to the ":" (colon) at the end of the last line that needs to be ";" (semi-colon) instead.
Walter Roberson
Walter Roberson am 30 Dez. 2022
Bearbeitet: Walter Roberson am 30 Dez. 2022
With minor changes:
e_inf = 11.7 ;
Wp1 = 1.0856e11;
gamma1 = 2.3518e9 ;
Wp2 = 3.4330e11;
gamma2 = 5.6747e9 ;
Wp3 = 1.0856e12;
gamma3 = 8.8952e9 ;
Wp4 = 3.4330e12;
gamma4 = 3.2292e10;
w1 = 1e13;
w2 = 1e10;
w3 = 1e15;
index = 0;
K = w1:w2:w3;
% Loop is not necessary!
e1 = e_inf - ((Wp1^2)./K.^2+1i*K*gamma1);
e2 = e_inf - ((Wp2^2)./K.^2+1i*K*gamma2);
e3 = e_inf - ((Wp3^2)./K.^2+1i*K*gamma3);
e4 = e_inf - ((Wp4^2)./K.^2+1i*K*gamma4);
f=K;
x=f;
figure
y1 = real(e1);
semilogx(x,y1, 'b-','linewidth',2, 'displayName', 'e_1')
hold on
y2 = real(e2);
semilogx(x,y2, 'g-', 'linewidth',2,'displayName', 'e_2'), grid on
y3 = real(e3);
semilogx(x,y3, 'r-', 'linewidth',2,'displayName', 'e_3'), grid on
y4 = real(e4);
semilogx(x,y4, 'black-', 'linewidth',2,'displayName', 'e_4'), grid on
hold off
L = legend('toggle');
L.Box = 'off';
L.Location = 'southeast';
Walter Roberson
Walter Roberson am 30 Dez. 2022
The "incomplete" is due to the ":" (colon) at the end of the last line that needs to be ";" (semi-colon) instead.
Yordani
Yordani am 30 Dez. 2022
Hello, I would like the Y axis to be the same
e_inf = 11.7 ;
Wp1 = 1.0856e11;
gamma1 = 2.3518e9 ;
Wp2 = 3.4330e11;
gamma2 = 5.6747e9 ;
Wp3 = 1.0856e12;
gamma3 = 8.8952e9 ;
Wp4 = 3.4330e12;
gamma4 = 3.2292e10;
w1 = 1e13;
w2 = 1e10;
w3 = 1e15;
index = 0;
K = w1:w2:w3;
% Loop is not necessary!
e1 = e_inf - ((Wp1^2)./K.^2+1i*K*gamma1);
e2 = e_inf - ((Wp2^2)./K.^2+1i*K*gamma2);
e3 = e_inf - ((Wp3^2)./K.^2+1i*K*gamma3);
e4 = e_inf - ((Wp4^2)./K.^2+1i*K*gamma4);
f=K;
x=f;
figure
y1 = real(e1);
semilogx(x,y1, 'b-','linewidth',2, 'displayName', 'e_1')
hold on
y2 = real(e2);
semilogx(x,y2, 'g-', 'linewidth',2,'displayName', 'e_2'), grid on
y3 = real(e3);
semilogx(x,y3, 'r-', 'linewidth',2,'displayName', 'e_3'), grid on
y4 = real(e4);
semilogx(x,y4, 'black-', 'linewidth',2,'displayName', 'e_4'), grid on
hold off
ylim([-300 50])
L = legend('toggle');
L.Box = 'off';
L.Location = 'southeast';
Walter Roberson
Walter Roberson am 30 Dez. 2022
You cannot see separate lines because when you expand the y axis to cover the same range as the other plot, then the data available for this plot has too little variation in y range to show separate lines.
Walter Roberson
Walter Roberson am 30 Dez. 2022
Your example plot has legend items such as 10^21 but I do not see which variable values that is intended to correspond to?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 31 Dez. 2022
Bearbeitet: Sulaymon Eshkabilov am 31 Dez. 2022

0 Stimmen

Here is the corrected code:
e_inf = 11.7 ;
Wp1 = 1.0856e11;
gamma1 = 2.3518e9 ;
Wp2 = 3.4330e11;
gamma2 = 5.6747e9 ;
Wp3 = 1.0856e12;
gamma3 = 8.8952e9 ;
Wp4 = 3.4330e12;
gamma4 = 3.2292e10;
w1 = 1e13;
w2 = 1e10;
w3 = 1e15;
index = 0;
K = w1:w2:w3;
% Loop is not necessary!
e1 = e_inf - ((Wp1^2)./K.^2+1i*K*gamma1);
e2 = e_inf - ((Wp2^2)./K.^2+1i*K*gamma2);
e3 = e_inf - ((Wp3^2)./K.^2+1i*K*gamma3);
e4 = e_inf - ((Wp4^2)./K.^2+1i*K*gamma4);
f=K;
x=f;
figure
y1 = real(e1); Wp1 = 1.0856e11;
gamma1 = 2.3518e9 ;
Wp2 = 3.4330e11;
gamma2 = 5.6747e9 ;
Wp3 = 1.0856e12;
gamma3 = 8.8952e9 ;
Wp4 = 3.4330e12;
gamma4 = 3.2292e10;
loglog(x,y1, 'b-.','linewidth',2, 'displayName', '\Gamma = 2.35*10^9')
hold on
y2 = real(e2);
loglog(x,y2, 'g-', 'linewidth',2.5,'displayName', '\Gamma = 5.6747*10^9'), grid on
y3 = real(e3);
loglog(x,y3, 'r--', 'linewidth',2,'displayName', '\Gamma = 8.8952*10^9'), grid on
y4 = real(e4);
loglog(x,y4, 'k:', 'linewidth',2,'displayName', '\Gamma = 3.2292*10^{10}'), grid on
hold off
ylim([11.55 11.705])
legend('toggle'); xlabel('$\omega$', 'interpreter', 'latex'); ylabel('$Re(\epsilon)$', 'interpreter', 'latex')

1 Kommentar

Walter Roberson
Walter Roberson am 31 Dez. 2022
No, they expect a graph in which the y4 values start about -300

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 30 Dez. 2022

Kommentiert:

am 31 Dez. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by