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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!