plot with two variables.

19 Ansichten (letzte 30 Tage)
shubhangi
shubhangi am 6 Okt. 2023
Kommentiert: Star Strider am 7 Okt. 2023
How to plot this equation "eq" with two variables "phi_rad" and "phi1_rad" (all other values are known and given at the start of the code (which is not shown below)
gamma1 = pi - acot ( ( (2*M1+M2)*cot(phi1_rad*r - phi_rad*r)*sin(phi_rad*r)-M2*cos(phi_rad*r+r*pi - r*phi1_rad) ) / ( M2*sin(phi_rad*r+r*pi - r*phi1_rad) + sin(phi_rad*r)*(2*M1+M2) ) ) ;
eq = ( ((2*M1+M2)*sin(r*pi - r*phi1_rad+gamma1))/sin(phi_rad*r+r*pi - r*phi1_rad+gamma1) ) - ( (M2*sin(gamma1))/sin(-phi1_rad*r + phi_rad*r+gamma1) ) - 2
Thanks in advance!

Akzeptierte Antwort

Star Strider
Star Strider am 6 Okt. 2023
I can’t run the code without the variables.
That aside, choose vector ranges for ‘phi_rad’ and ‘phi1_rad’ and use the ndgrid function to create matrices from them. After that, one option is to reshape the matrices into column vectors, so that all combinations of each variable are present in the functions. Plotting them after that can either use plot, plot3, mesh or surf, depending on what you want to do.
gamma1 = @(phi_rad,phi1_rad) phi_rad .* exp(-0.1 * phi1_rad);
eq = @(phi_rad,phi1_rad) phi1_rad .* exp(-(phi1_rad - pi).^2);
N = 25;
phi_rad = linspace(0, 2*pi, N);
phi1_rad = linspace(-pi, pi, N);
[Phi1m,Phim] = ndgrid(phi1_rad, phi_rad);
figure
plot3(Phi1m(:),Phim(:), gamma1(Phi1m(:),Phim(:)))
hold on
plot3(Phi1m(:),Phim(:), eq(Phi1m(:),Phim(:)))
hold off
figure
surf(Phi1m, Phim, gamma1(Phi1m,Phim))
hold on
surf(Phi1m, Phim, eq(Phi1m,Phim))
hold off
.
  2 Kommentare
shubhangi
shubhangi am 6 Okt. 2023
This is very helpful! Thank you so much!
Star Strider
Star Strider am 7 Okt. 2023
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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