plot with two variables.

20 visualizaciones (últimos 30 días)
shubhangi
shubhangi el 6 de Oct. de 2023
Comentada: Star Strider el 7 de Oct. de 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!

Respuesta aceptada

Star Strider
Star Strider el 6 de Oct. de 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 comentarios
shubhangi
shubhangi el 6 de Oct. de 2023
This is very helpful! Thank you so much!
Star Strider
Star Strider el 7 de Oct. de 2023
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by