Error using dot A and B must be same size in MATLAB (moment Vectors)

Hi
I am reading a scientific paper and trying to reproduce their work. The following are the equations I am working with
solving for this equation
here is my code
syms u_A1 u_A2 u_A3 u_A4 M_A V_A M_B V_B alpha B_r u_0 mu_0 r d pi r11 r12 r13 r14 r21 r22 r23 r24 e_x e_y
mu_a1 = -M_A*V_A;
mu_a2 = -M_A*V_A;
mu_a3 = -M_A*V_A
mu_a4 = -M_A*V_A
mu_A=[mu_a1 mu_a2 mu_a3 mu_a4];
e_x= 1;
e_y=1;
Vector= [e_x ; e_y];
B1=[M_B*V_B*cos(alpha) M_B*V_B*sin(alpha)];
B2=[-M_B*V_B*sin(alpha) M_B*V_B*cos(alpha)];
B3=[-M_B*V_B*cos(alpha) -M_B*V_B*sin(alpha)];
B4=[M_B*V_B*sin(alpha) -M_B*V_B*cos(alpha)];
mu_B1= B1*Vector;
mu_B2= B2*Vector;
mu_B3= B3*Vector;
mu_B4= B4*Vector;
mu_B=[mu_B1;mu_B2;mu_B3;mu_B4];
r11= [r-r*cos(alpha)+d -r*sin(alpha)]*Vector;
r21= [(-r*cos(alpha)) -(r+r*sin(alpha)+d)]*Vector;
r31= [-(r+r*cos(alpha)+d) -(r*sin(alpha))]*Vector;
r41= [(-r*cos(alpha)) (r-r*sin(alpha)+d)]*Vector;
r12= [(r-r*sin(alpha)+d) r*cos(alpha)]*Vector;
r22= [-(r*sin(alpha)) -(r-r*cos(alpha)+d)]*Vector;
r32= [-(r+r*sin(alpha)+d) r*cos(alpha)]*Vector;
r42= [-(r*sin(alpha)) (r+r*cos(alpha)+d)]*Vector;
r13= [r+r*cos(alpha)+d r*sin(alpha)]*Vector;
r23= [r*cos(alpha) -(r-r*sin(alpha)+d)]*Vector;
r33= [-(r-r*cos(alpha)+d) r*sin(alpha)]*Vector;
r43= [r*cos(alpha) (r+r*sin(alpha)+d)]*Vector;
r14= [(r+r*sin(alpha)+d) -r*cos(alpha)]*Vector;
r24= [r*sin(alpha) -(r+r*cos(alpha)+d)]*Vector;
r34= [-(r-r*sin(alpha)+d) -r*cos(alpha)]*Vector;
r44= [r*sin(alpha) (r-r*cos(alpha)+d)]*Vector;
r=[r11 r21 r31 r41; r12 r22 r32 r42; r13 r23 r33 r43; r14 r24 r34 r44];
dotA= dot(r,mu_A);
I am getting this error "Error using dot A and B must be same size"

 Accepted Answer

You are not exactly doing what's done in the reference.
s = size(r);
B = zeros(s,'sym');
for m=1:s(1)
for n=1:s(2)
B(m,n) = dot(mu_A(m),r(m,n))/norm(r(m,n),2)^3;
end
end
%B = -mu_not*B/(4*pi)

4 Comments

Thank you for your answer, but did you neglect the gradient? how can I deal with it?
"but did you neglect the gradient?"
I must have overlooked the gradient sign in the formula, my bad.
"how can I deal with it?"
Just use the function gradient.
Also, change the name of the matrix to avoid over-writing, as r is defined as an independent symbolic variable -
%Name changed
R=[r11 r21 r31 r41; r12 r22 r32 r42; r13 r23 r33 r43; r14 r24 r34 r44];
s = size(R);
B = zeros(s,'sym');
for m=1:s(1)
for n=1:s(2)
B(m,n) = gradient(dot(mu_A(m),R(m,n))/norm(R(m,n),2)^3, vars);
end
end
%B = -mu_not*B/(4*pi)
Here, vars are the symbolic variables w.r.t whom you are calculating the gradient of the input.
(My guess is that the variables are r and d)
I really appreciate your help, thanks a lot

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Community Treasure Hunt

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

Start Hunting!