Graph Multiple Functions in MATLAB

조회 수: 1 (최근 30일)
Jun Young Choi
Jun Young Choi 2020년 11월 14일
댓글: Ameer Hamza 2020년 11월 14일
rr=140*(1-(0.02/r)^2)+140*(1-4*(0.02/r)^2+3*(0.02/r)^4)*cosd(2*theta);
As for the equation above, I want to plot a graph for theta=0 degrees, 22.5 degrees, 67.5 degrees, and 90 degrees.
Thus the graph would have multiple lines, and there also needs to a legend to show which line is which.
Please help.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 14일
편집: Ameer Hamza 2020년 11월 14일
This shows an example of how it can be done
r = linspace(0.1, 1, 100);
thetas = [0 22.5 67.5 90];
figure();
axes();
hold on
for i = 1:numel(thetas)
theta = thetas(i);
rr = 140*(1-(0.02./r).^2)+140*(1-4*(0.02./r).^2+3*(0.02./r).^4).*cosd(2*theta);
plot(r, rr);
end
legend_strs = compose('$\\theta=%.1f$', thetas);
legend(legend_strs, 'Interpreter', 'latex', 'Location', 'best', 'FontSize', 16);
I have used element-wise operators (.* ./) in my code. Read about them here: https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
  댓글 수: 2
Jun Young Choi
Jun Young Choi 2020년 11월 14일
Thank you!
Ameer Hamza
Ameer Hamza 2020년 11월 14일
I am glad to be of help!

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

추가 답변 (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