Plot returning all zeros
Afficher commentaires plus anciens
Hi, I'm not the most experienced Matlab user, and I'm trying to plot 2 functions as a function of a variable from 0 to 360 degrees. When I type in a value for t2. Apo4x and Apo4y return values. The problem is when I set t2 to a range of values, Apo4x and Apo4y return 0 for every iteration.
Below is my code.
a=1; b=4; c=8; d=1.3; k=0.3; g=5;
t2dot=10;
t2ddot=0;
t2=(pi/180)*[0:5:360]
t4=atan2(a*sin(t2)+k, a*cos(t2)+d);
f=(a*cos(t2)+d)/cos(t4);
A=[f*sin(t4),-cos(t4);-f*cos(t4),-sin(t4)];
B=[t2dot*a*sin(t2);-t2dot*a*cos(t2)];
C=A\B;
t4dot=C(1);
fdot=C(2);
Q1=-t2dot*a*sin(t2)-t4dot*b*sin(t4)-fdot*cos(t4)+t4dot*f*sin(t4);
Q2=t2dot*a*cos(t2)+t4dot*b*cos(t4)-fdot*sin(t4)-t4dot*f*cos(t4);
t5=asin((g-b*sin(t4))/c);
D=[c*sin(t5),-1;-c*cos(t5),0];
E=[Q1;Q2];
F=D\E;
t5dot=F(1);
hdot=F(2);
Q3=-t2ddot*a*sin(t2)-t2dot^2*a*cos(t2)+t4dot^2*f*cos(t4)+t4dot*fdot*sin(t4);
Q4=t2ddot*a*cos(t2)-t2dot^2*a*sin(t2)+t4dot^2*f*sin(t4)-t4dot*fdot*cos(t4);
G=[-f*sin(t4),-t4dot*sin(t4)+cos(t4);f*cos(t4),t4dot*cos(t4)+sin(t4)];
H=[Q3;Q4];
J=G\H;
t4ddot=J(1);
fddot=J(2);
Q5=-t4ddot*b*sin(t4)-t4dot^2*b*cos(t4)-t5dot^2*c*cos(t5);
Q6=t4ddot*b*cos(t4)-t4dot^2*b*sin(t4)-t5dot^2*c*sin(t5);
K=[c*sin(t5),-1;-c*cos(t5),0];
L=[Q5;Q6];
M=K\L;
t5ddot=M(1);
hddot=M(2);
Apo4x=-t4ddot*b*sin(t4)-t4dot^2*b*cos(t4)-t5ddot*(c/2)*sin(t5)-t5dot^2*(c/2)*cos(t5);
Apo4y=t4ddot*b*cos(t4)-t4dot^2*b*sin(t4)+t5ddot*(c/2)*cos(t5)-t5dot^2*(c/2)*sin(t5);
plot(t2,Apo4x,'-r',t2,Apo4y,'-b')
and here is a similar code I wrote that didn't have said problem. Why does the bottom code work while the top doesn't? How can I fix this? Thanks for your time!
format compact
a=20;
b=55;
c=8;
p=30;
t2=(pi/180)*[0:5:360]
t2dot=10;
t3=asin((a*sin(t2)-c)/b);
t3dot=-t2dot*(a*cos(t2))/(b*cos(t3));
ddot=-t2dot*a*sin(t2)+t3dot*b*sin(t3);
Vpx=-t2dot*a*sin(t2)+t3dot*(b*sin(t3)-28.8*sin(t3+20.95*pi/180))
Vpy=t2dot*a*cos(t2)-t3dot*(b*cos(t3)+28.7*cos(t3+20.95*pi/180));
plot(t2,Vpx,'-r',t2,Vpy,'-b')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!