Help with fsolve in for loop!
2 views (last 30 days)
Show older comments
Hello,
I'm trying to plot the path of motion of a point in a 4 bar kinematic system. If you don't understand that than i basically have two unknowns (angles, x(1) and x(2)) and two equations that i'm trying to solve. To do this i have a for loop getting each point of the path, but I continue to experience problems.
I've been playing around with the variables and everything, I feel like I'm very close. I was wondering if someone could help me troubleshoot this:
syms x
R1=4;
R3=8;
R4=6;
R5=12;
Th4=3*pi/2;
Th5=pi;
i=0;
r=12;
for Th1=0:.1:2*pi
i=i+1;
expr1=R1*cos(Th1)+r*cos(x(1))+R3*cos(x(2))+R4*cos(Th4)+R5*cos(Th5);
expr2=R1*sin(Th1)+r*sin(x(1))+R3*sin(x(2))+R4*sin(Th4)+R5*sin(Th5);
[Th,fval]=fsolve(expr1,expr2);
px(i)=R1*cos(Th1)+(r/2)*cos(Th(1));
py(i)=R1*sin(Th1)+(r/2)*sin(Th(1));
end
hold on
xlabel('X position')
ylabel('Y position')
title('My four-bar output')
plot(px,py)
hold off
The error i get for this is: Error using mupadmex Error in MuPAD command: Index exceeds matrix dimensions.
Error in sym/subsref (line 1410) B = mupadmex('symobj::subsref',A.s,inds{:});
Error in kinematic2 (line 14) expr1=R1*cos(Th1)+r*cos(x(1))+R3*cos(x(2))+R4*cos(Th4)+R5*cos(Th5);
0 Comments
Answers (1)
Andrew Newell
on 15 Feb 2012
The source of the error is probably your references to x(1) and x(2), because you have defined x as a scalar in syms x. Why not replace x(1) by x and x(2) by y?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!