Graph Multiple Functions in MATLAB
1 view (last 30 days)
Show older comments
Jun Young Choi
on 14 Nov 2020
Commented: Ameer Hamza
on 14 Nov 2020
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 Comments
Accepted Answer
Ameer Hamza
on 14 Nov 2020
Edited: Ameer Hamza
on 14 Nov 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!