Solving a system of equations symbolically

3 views (last 30 days)
I am trying to solve a system of four equations in four variables symbolically. The code is attached below. The four variables in question are d1, d2, d12 and thta12 (the remaining symbols in the code are parameters). This system of equations can be solved (and I did it by hand). However, when I run this code, I get the following message and no solution is obtained.
Warning: Unable to find explicit solution. For options, see help.
> In sym/solve (line 317)
In untitled (line 16)
I have attached a picture of my analytical solution to the problem to show that it indeed exists (ignore the figure on top). Equations 1 to 4 are the equations I entered in my code.
I tried removing the .....'ReturnConditions', true) part of my solve() function. Doing so returns expressions for d1, d2, d12 and thta12 which are correct (but are far more complicated than they need to be). Why is this happening?
syms F0 R1 R2 d1 d2 d12 thta thta12 m1 m2
assume(thta12,'real')
assume(thta, 'real')
assume(thta~=0)
eq1=((F0/R1)*(R1-d1)*cos(thta))-((F0/(R1+R2))*(R1+R2-d12)*cos(thta12))==0
eq2=((F0/R1)*(R1-d1)*sin(thta))-((F0/(R1+R2))*(R1+R2-d12)*sin(thta12))-m1==0
eq3=((F0/(R1+R2))*(R1+R2-d12)*cos(thta12))-((F0/R2)*(R2-d2)*cos(thta))==0
eq4=((F0/(R1+R2))*(R1+R2-d12)*sin(thta12))+((F0/R2)*(R2-d2)*sin(thta))-m2==0
S=solve(eq1,eq2,eq3,eq4,[d1,d2, d12, thta12],'PrincipalValue', true, 'ReturnConditions',true)

Accepted Answer

Torsten
Torsten on 15 Sep 2022
Better ?
syms F0 R1 R2 d1 d2 d12 thta thta12 m1 m2
assume(thta12,'real')
assume(thta, 'real')
assume(thta~=0)
eq1=((F0/R1)*(R1-d1)*cos(thta))-((F0/(R1+R2))*(R1+R2-d12)*cos(thta12))==0;
eq2=((F0/R1)*(R1-d1)*sin(thta))-((F0/(R1+R2))*(R1+R2-d12)*sin(thta12))-m1==0;
eq3=((F0/(R1+R2))*(R1+R2-d12)*cos(thta12))-((F0/R2)*(R2-d2)*cos(thta))==0;
eq4=((F0/(R1+R2))*(R1+R2-d12)*sin(thta12))+((F0/R2)*(R2-d2)*sin(thta))-m2==0;
S=solve(eq1,eq2,eq3,eq4,[d1,d2, d12, thta12]);%,'PrincipalValue', true, 'ReturnConditions',true)
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
simplify(S.d1)
ans = 
simplify(S.d2)
ans = 
simplify(S.d12)
ans = 
simplify(S.thta12)
ans = 
  3 Comments
Torsten
Torsten on 15 Sep 2022
Edited: Torsten on 15 Sep 2022
The first components of the four vectors form one solution of the system, the second components of the four vectors form a second solution of the system.
Walter Roberson
Walter Roberson on 15 Sep 2022
You have a situation in which d12 can have two different solutions, and each solution has its own theta value. So sol.d12(1) corresponds to sol.theta(1) and sol.d12(2) corresponds to sol.theta(2)
Meanwhile, the d1 and d2 are common for both solutions. In theory solve() could have represented that by scalar sol.d1 and sol.d2, but instead solve() duplicates the values so that you can index each of the variables by the same index to get corresponding values, without having to test whether the solutions are scalar or not.
... Besides, you will get cases where a solution is in common with only a subset of other solutions and it would get confusing to create some kind of nesting that used scalar answers to match with a subset... Easier all around to just duplicate the solution as needed and as applicable.

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!