Why is Matlab not plotting properly and crashing?

1 view (last 30 days)
Bruce
Bruce on 25 Oct 2014
Commented: Bruce on 11 Nov 2014
I am a Mechanical engineering student and wrote a code to simulate a quick return mechanism.
Here is the code -
_ _ *% Whitworth's quick return mechanism %
choice=menu('Whitworth quick return mechanism','Default values','User defined values'); if choice==1 prompt={'Length of slotted lever','Length of the arm','Angular speed of the lever '}; dgl_title='Enter the values'; def={'50','75','3'}; m=inputdlg(prompt,dgl_title,3,def);
l2=str2double(m{1});
w2=str2double(m{3});
l4=str2double(m{2});
end
if choice==2 prompt1={'Length of slotted lever','Length of the arm','Angular speed of the lever'}; dgl_title1='Enter the values'; m=inputdlg(prompt1,dgl_title1);
l2=str2double(m{1});
w2=str2double(m{3});
l4=str2double(m{2});
end
l1=20; l5=60; t=0;
for t=0:0.01:10 t2=w2*t; t1=pi/2; l3=sqrt((l1*cos(t1)+l2*cos(t2))^2+(l1*sin(t1)+l2*sin(t2))^2); t3=atan2((l1*sin(t1)+l2*sin(t2)),(l1*cos(t1)+l2*cos(t2)));
% Position Analysis
subplot (2,2,[1 3]);
title('Simulation');
plot([0 l2*cos(t2)],[l1 l1+l2*sin(t2)],'b','Linewidth',3);
hold on;
rectangle('Position',[l2*cos(t2)-2.5,17.5+l2*sin(t2),5,5],'FaceColor','k');
subplot (2,2,[1 3]);
plot([0 l3*cos(t3)],[0 l3*sin(t3)],'b','Linewidth',3);
hold on;
subplot (2,2,[1 3]);
plot([l3*cos(t3) l4*cos(t3)],[l3*sin(t3) l4*sin(t3)],'Linewidth',3);
hold on;
subplot (2,2,[1 3]);
plot([l4*cos(t3) l4*cos(t3)-sqrt(l5^2-(l4*sin(t3)-40)^2)],[l4*sin(t3) 40],'b','Linewidth',3);
hold on;
rectangle('Position',[l4*cos(t3)-sqrt(l5^2-(l4*sin(t3)-40)^2)-2.5,40-2.5,5,5],'FaceColor','k');
title('Simulation');
axis equal;
axis([-l2-150 l2+150 -l4-20 l4+20]);
%Velocity Analysis
subplot (2,2,2);
title('Velocity Analysis');
quiver(0,0,w2*l2*sin(t2)*10/9,w2*l2*cos(t2)*10/9);
hold on;
w3=((l2*w2*cos(t2)*cos(t3)+l2*w2*sin(t2)*sin(t3))/l3);
quiver(0,0,w3*l3*sin(t3)*10/9,w3*l3*cos(t3)*10/9);
hold on;
plot([w2*l2*sin(t2) w3*l3*sin(t3)],[w2*l2*cos(t2) w3*l3*cos(t3)],'r') ;
hold on;
title('Velocity Analysis');
axis equal;
axis([-l2*w2-2*w2 l2*w2+2*w2 -l2*w2-2*w2 l2*w2+2*w2]);
%Acceleration Analysis
subplot (2,2,4);
A2n=l2*w2*w2;
A2t=0;
A3n=l3*w3*w3;
R3=((l3*w3*sin(t3)-l2*w2*sin(t2))/cos(t3));
a3=((-1*l2*w2*w2*cos(t2-t3)-2*R3*w3)/l3);
A3t=a3*l3;
quiver(0,0,l2*w2*w2*cos(t2)*10/9,l2*w2*w2*sin(t2)*10/9);
hold on;
quiver(0,0,l3*w3*w3*cos(t3)*10/9,l3*w3*w3*sin(t3)*10/9);
hold on;
quiver(l3*w3*w3*cos(t3),l3*w3*w3*sin(t3),-l3*a3*sin(t3)*10/9,l3*a3*cos(t3)*10/9);
hold on;
quiver(l3*w3*w3*cos(t3)-l3*a3*sin(t3),l3*a3*cos(t3)+l3*w3*w3*sin(t3),A3n*cos(t3)*10/9,A3n*sin(t3)*10/9);
hold on;
plot([l3*w3*w3*cos(t3)-l3*a3*sin(t3)+A3n*cos(t3) l2*w2*w2*cos(t2)],[l3*a3*cos(t3)+l3*w3*w3*sin(t3)+A3n*sin(t3) l2*w2*w2*sin(t2)],'k');
title('Acceleration Analysis');
axis equal;
pause(0.01);
clf('reset');
end* _ _
When I execute on my computer, the simulation is not proper, i.e the plotting is very slow and when I attempt to close the plot, Matlab crashes saying it has an internal problem. The code works perfectly with other computers.
I tried everything. Reinstalling a number of times and yet the problem exists.\
I have a Dell laptop with windows 8.1 and an AMD radeon HD 8730M up to date.
I would be grateful if anyone can help.

Answers (1)

Image Analyst
Image Analyst on 25 Oct 2014
I didn't run it since you said it runs fine on other computers, so it's something unique with your computer only and nothing in the code would make my computer crash. Anyway, I don't have Windows 8.1.
  3 Comments
Image Analyst
Image Analyst on 25 Oct 2014
Bruce, it seems to run but it throws a warning
Warning: Imaginary parts of complex X and/or Y arguments ignored
> In test2 at 49
and is very slow - takes several minutes to finish.
Bruce
Bruce on 11 Nov 2014
Yes, I am not able to solve the problem still. I am changing the code a bit. Relieved to know my Matlab is proper. Thanks for the help.
If at all there is any error you find in the code, please let me know.

Sign in to comment.

Categories

Find more on Graphics Performance 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!