plot with two variables.

조회 수: 20 (최근 30일)
shubhangi
shubhangi 2023년 10월 6일
댓글: Star Strider 2023년 10월 7일
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
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
.
  댓글 수: 2
shubhangi
shubhangi 2023년 10월 6일
This is very helpful! Thank you so much!
Star Strider
Star Strider 2023년 10월 7일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by