Debugging code for matrix dimensions

I am trying to calculate the velocity and accelerations of a slider in a crank slider mechanism.
The code below gives the error:
Error using /
Matrix dimensions must agree.
Error in olaitan_2 (line 9)
w=theta/t;
The crank motion is constrained to move from 90 degrees to 60 degrees
How do I fix this ?
Thanks.
%calculation of accelaration of pressing block in crank slider mechanism
L=0.36;
R=0.12;
theta=pi/2:pi/180:(1/3)*pi;
phi=(1/6)*pi:pi/180:(1/18)*pi;
X=L*cos(phi)+R*cos(theta);
%cos(phi)=sqrt[1-(R/L).^2*sin(theta).^2;
t=0:(5/30):5;
w=theta/t;
Dphi= w*[((R/L)*cos(phi))/(1-(R/L).^2*sin (theta).^2).^0.5];
DDphi=(w.^2*(R/L)*sin(theta)*[(R/L.^2)-1])/[1-(R/L.^2)*sin(theta).^2].^1.5;
DX= -w*((1+Dphi)/w)*(R/L)*sin(theta)*L;
DDX= -w.^2*(R/L)*[cos(theta)+((DDphi/w.^2)*sin(theta))+((Dphi/w)*cos(theta))]*L;
plot(t,DX,t,DDX)
grid on;

Answers (1)

t=linspace(0,5,length(theta));
t and theta length must be same, thats why I have changed t with linspace, its creates the same length vector as theta.
Also please note on the following
theta=pi/2:pi/180:(1/3)*pi;
^.....initial:step (increment):final
The last (1/3)*pi is less than initial (pi/2), same case for phi also
See example:
>> a=1:1:4
a =
1 2 3 4
>> b=4:2:3
b =
1×0 empty double row vector
Now modify the code accordingly, any issue let me know.

3 Comments

Please note I have changed the phi and t to linearly spaced vector. Also [ ] represents vector in matlab, not multiplication, you can use multiple brackets, like ((a*b)*c), also .* reperesents vector multiplecation, read the Matlab documentation for details.
L=0.36;
R=0.12;
theta=pi/2:pi/180:pi;
phi=linspace((1/6)*pi,pi,length(theta));
X=L*cos(phi)+R*cos(theta);
%cos(phi)=sqrt[1-(R/L).^2*sin(theta).^2;
t=linspace(0,5,length(theta));
w=theta./t;
Dphi= w*(((R/L)*cos(phi))/(1-(R/L).^2*sin (theta).^2).^0.5);
DDphi=((w.^2).*(R/L).*sin(theta)*((R/L.^2)-1))/(1-(R/L.^2)*sin(theta).^2).^1.5;
DX= -w.*((1+Dphi)./w).*(R/L).*sin(theta).*L;
DDX= -(w.^2).*(R/L).*(cos(theta)+((DDphi./(w.^2)).*sin(theta))+((Dphi./w).*cos(theta)))*L;
plot(t,DX,t,DDX)
grid on;
Yes I know the intitial theta is more than the final.
That is how the machine is constrained to move for the slider to move forward.
That is why I made it that way
Yes, but length must be same to do further calculation.

Sign in to comment.

Categories

Products

Release

R2016a

Asked:

on 25 Jul 2019

Commented:

on 26 Jul 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!