unable to use solve or fsolve for linear system
2 views (last 30 days)
Show older comments
Dhanush Srikanth
on 26 Jun 2022
Commented: Dhanush Srikanth
on 26 Jun 2022
syms R1 R2 R3 R4
COM = [-6,0,10]
r1 = [-54.2,-27.5,-16.4]
r2 = [-54.2,27.5,-16.4]
r3 = [42.9,-27.5,-16.4]
r4 = [42.9,27.5,-16.4]
rr1 = [0,0,R1]
rr2 = [0,0,R2]
rr3 = [0,0,R3]
rr4 = [0,0,R4]
mg = [0,0,980.65*16631]
eq(1) = cross(r1-r2,rr2) + cross(r1-r3,rr3) + cross(r1-COM,mg) + cross(r1-r4,rr4) == [0,0,0]
eq(2) = cross(r2-r1,rr1) + cross(r2-r3,rr3) + cross(r2-COM,mg) + cross(r2-r4,rr4) == [0,0,0]
eq(3) = cross(r3-r2,rr2) + cross(r3-r1,rr1) + cross(r3-COM,mg) + cross(r3-r4,rr4) == [0,0,0]
eq(4) = cross(r4-r2,rr2) + cross(r4-r3,rr3) + cross(r4-COM,mg) + cross(r4-r1,rr1) == [0,0,0]
j = fsolve(eq,[R1,R2,R3,R4])
im trying to solve the above system of linear equations for R1 R2 R3 & R4
the error is
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
L_tilde2 = builtin('subsasgn',L_tilde,struct('type','()','subs',{varargin}),R_tilde);
C = privsubsasgn(L,R,inds{:});
0 Comments
Accepted Answer
Torsten
on 26 Jun 2022
Edited: Torsten
on 26 Jun 2022
Seems your equations are not independent.
syms R1 R2 R3 R4
COM = [-6,0,10];
r1 = [-54.2,-27.5,-16.4];
r2 = [-54.2,27.5,-16.4];
r3 = [42.9,-27.5,-16.4];
r4 = [42.9,27.5,-16.4];
rr1 = [0,0,R1];
rr2 = [0,0,R2];
rr3 = [0,0,R3];
rr4 = [0,0,R4];
mg = [0,0,980.65*16631];
%eq(1) = cross(r1-r2,rr2) + cross(r1-r3,rr3) + cross(r1-COM,mg) + cross(r1-r4,rr4) == [0,0,0]
%eq(2) = cross(r2-r1,rr1) + cross(r2-r3,rr3) + cross(r2-COM,mg) + cross(r2-r4,rr4) == [0,0,0]
%eq(3) = cross(r3-r2,rr2) + cross(r3-r1,rr1) + cross(r3-COM,mg) + cross(r3-r4,rr4) == [0,0,0]
%eq(4) = cross(r4-r2,rr2) + cross(r4-r3,rr3) + cross(r4-COM,mg) + cross(r4-r1,rr1) == [0,0,0]
%j = fsolve(eq,[R1,R2,R3,R4])
cross(r1-r2,rr2) + cross(r1-r3,rr3) + cross(r1-COM,mg) + cross(r1-r4,rr4)
cross(r2-r1,rr1) + cross(r2-r3,rr3) + cross(r2-COM,mg) + cross(r2-r4,rr4)
cross(r3-r2,rr2) + cross(r3-r1,rr1) + cross(r3-COM,mg) + cross(r3-r4,rr4)
cross(r4-r2,rr2) + cross(r4-r3,rr3) + cross(r4-COM,mg) + cross(r4-r1,rr1)
A = [0 -55 0 -55;55 0 55 0; 0 0 97.1 97.1;-97.1 -97.1 0 0];
rank(A)
b = [3588021833/8;-3588021833/8;-1648577405738025/2097152;836259700628521/1048576];
sol = A\b;
R1 = sol(1)
R2 = sol(2)
R3 = sol(3)
R4 = sol(4)
More Answers (1)
Walter Roberson
on 26 Jun 2022
those cross() calls each return a vector, and you compare the vector to [0 0 0] giving a vector result. You then try to store the vector in a scalar location.
If you were to store the entire vector, then when you got to the fsolve you would have four sets of 3 equations, for a total of 12 equations. And you are trying to fsolve the 12 for four variables. That is unlikely to succeed.
See Also
Categories
Find more on Matrices and Arrays 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!