Error using * Incorrect dimensions for matrix multiplication

3 views (last 30 days)
How can I fix
Error using *
Incorrect dimensions for matrix multiplication. Check that the
number of columns in the first matrix matches the number of rows in
the second matrix. To perform elementwise multiplication, use '.*'.
Error in Untitled (line 55)
s23 = -((a3+a2*c3)*Pz)+(c1*Px+s1*Py)*(a2*s3-d4);
?
Here is the code
% *** Program ik_Algebraic.m
...Solving inverse kinematics...
...Created on March 2021 by KKK.Adams.***
%%
clear ; close all; clc;
% Link lenghts & Offsets in Millimeters(mm)
a2=380; a3=0; d3=0; d4=351; L5=89;
% Finding Px, Py, Px
p1x= 202.90; p1y= 55.85; p1z =-449.09;
p2x= 232.91; p2y= 49.08; p2z =-465.79;
p3x= 199.39; p3y= 31.37; p3z =-445.48;
p4x= 196.96; p4y= 55.17; p4z =-459.50;
Mx= 250.32; My= 44.14; Mz= -395.82;
p1_p2= 35; p1_p3= 25; p1_p4= 12;
nx = (p2x-p1x)/p1_p2; ny= (p2y-p1y)/p1_p2;nz= (p2z-p1z)/p1_p2;
disp('nx = '),disp(nx)
disp('ny = '),disp(ny)
disp('nz = '),disp(nz)
sx = (p3x-p1x)/p1_p3; sy= (p3y-p1y)/p1_p3;sz= (p3z-p1z)/p1_p3;
disp('sx = '),disp(sx)
disp('sy = '),disp(sy)
disp('sz = '),disp(sz)
ax = (p4x-p1x)/p1_p4; ay= (p4y-p1y)/p1_p4;az= (p4z-p1z)/p1_p4;
disp('ax = '),disp(ax)
disp('ay = '),disp(ay)
disp('az = '),disp(az)
%
Pxfp= 206.2437; Pyfp= 39.0914; Pzfp= -472.9750; %from forward kinematics
Px = (Pxfp-L5*ax); Py = (Pyfp-L5*ay); Pz = (Pzfp-L5*az);
% Finding joint angle 1
theta1 = atan2(Py,Px)-atan2(d3,[1 -1]*sqrt(Px^2+Py^2-d3^2)); % +/-...[1 -1]
theta1 = rad2deg(theta1);
disp('theta1 ='),disp(theta1)
%
c1 = cos(theta1);
s1 = sin(theta1);
% Finding joint angle 3
K = (Px^2+Py^2+Pz^2-a2^2-a3^2-d3^2-d4^2)/(2*a2);
disp('K= '),disp(K)
%
theta3 = atan2(a3,d4)-atan2(K,[1 -1]*sqrt(a3^2+d4^2-K^2)); % +/-...[1 -1]
theta3 = rad2deg(theta3);
disp('theta3 ='),disp(theta3)
%
c3 = cos(theta3);
s3 = sin(theta3);
% Finding joint angle 2
s23 = -((a3+a2*(c3))*Pz)+((c1)*Px+s1*Py)*(a2*(s3-d4));
c23 = (-d4+a2*s3)*Pz+(c1*Px+s1*Py)*(a2*c3+a3);
theta23 = atan2(s23,c23);
theta23 = rad2deg(theta23);
theta2 = theta23 - theta3;
disp('theta2 ='),disp(theta2)

Accepted Answer

DGM
DGM on 29 Mar 2021
c1,c3,s1,s3 are vectors. If you want elementwise multiplication, use that.
s23 = -((a3+a2*c3)*Pz) + (c1*Px+s1*Py).*(a2*(s3-d4));
c23 = (-d4+a2*s3)*Pz + (c1*Px+s1*Py).*(a2*c3+a3);
Don't know if that's the intention.
  1 Comment
Konard Adams
Konard Adams on 30 Mar 2021
Worked that you very much!
% Finding joint angle 2
s23 = -(a3+a2*c3)*Pz + (c1*Px+s1*Py).*(a2*s3-d4);
c23 = (-d4+a2*s3)*Pz + (c1*Px+s1*Py).*(a2*c3+a3);
theta23 = atan2(s23,c23);
theta23 = rad2deg(theta23);
theta2 = theta23 - theta3;
disp('theta2 ='),disp(theta2)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!