How can I plot two different figures with a for loop when my variables change with each iteration of the loop?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello. I am trying to solve a system of equations, and I need to graph the results of the velocity according to the initial angle of my system.
figure
for th = 0:1:65
eqn1=((0.3.*sind(th2)).*(om_AB))-((0.3.*sind(th3)).*(om_BC))==((0.275.*sind(th)).*(0.0349));
eqn2=((0.3.*cosd(th2)).*(om_AB))+((0.3.*cosd(th3)).*(om_BC))==-((0.275.*cosd(th)).*(0.0349));
sol = solve([eqn1, eqn2], [om_AB, om_BC]);
sol1 = double(sol.om_AB);
sol2 = double(sol.om_BC);
plot(th,sol1)
plot(th,sol2)
hold on
end
When I run the code, I get the results, but I only get one figure and it is empty. I have a section that calculates the values of th2 and th3 above these lines of code, so I don't think that is the mistake. Those values also change with th, so they are also matrix systems, hence why I used .* in every multiplication, as I do not know where it is necessary that I put the dot, and I did not want to make a mistake with that part of the code.
How could I get two different figures, one for each of my solutions, that contain the values gotten from each iteration of the for loop?
Thanks!
0 Kommentare
Antworten (1)
I-Chun
am 9 Mai 2023
Because the sol1, sol2 haven't been put into vector. Vector is needed when using "plot".
syms om_AB om_BC
th2 = rand;
th3 = rand;
sol1 = [];
sol2 = [];
figure
for th = 0:1:65
eqn1=((0.3.*sind(th2)).*(om_AB))-((0.3.*sind(th3)).*(om_BC))==((0.275.*sind(th)).*(0.0349));
eqn2=((0.3.*cosd(th2)).*(om_AB))+((0.3.*cosd(th3)).*(om_BC))==-((0.275.*cosd(th)).*(0.0349));
sol = solve([eqn1, eqn2], [om_AB, om_BC]);
sol1(end+1) = double(sol.om_AB);
sol2(end+1) = double(sol.om_BC);
end
th = 0:1:65;
plot(th,sol1)
hold on
plot(th,sol2)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!