Graph Multiple Functions in MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!