plot with two variables.
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
Réponse acceptée
Star Strider
le 6 Oct 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

