plot with two variables.
20 次查看(过去 30 天)
显示 更早的评论
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!
采纳的回答
Star Strider
2023-10-6
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
.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

