unable to use solve or fsolve for linear system

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{:});

 Accepted Answer

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)
ans = 
cross(r2-r1,rr1) + cross(r2-r3,rr3) + cross(r2-COM,mg) + cross(r2-r4,rr4)
ans = 
cross(r3-r2,rr2) + cross(r3-r1,rr1) + cross(r3-COM,mg) + cross(r3-r4,rr4)
ans = 
cross(r4-r2,rr2) + cross(r4-r3,rr3) + cross(r4-COM,mg) + cross(r4-r1,rr1)
ans = 
A = [0 -55 0 -55;55 0 55 0; 0 0 97.1 97.1;-97.1 -97.1 0 0];
rank(A)
ans = 3
b = [3588021833/8;-3588021833/8;-1648577405738025/2097152;836259700628521/1048576];
sol = A\b;
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 3.144153e-17.
R1 = sol(1)
R1 = -8.5635e+06
R2 = sol(2)
R2 = 3.5012e+05
R3 = sol(3)
R3 = 4.0891e+05
R4 = sol(4)
R4 = -8.5047e+06

More Answers (1)

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.

1 Comment

Right, so should I store the result from each equation seperately and then pick any 4 equations and then use them in solve?

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!