MATLAB Answers

Solving non linear equations sytem

1 ビュー (過去 30 日間)
dd hh
dd hh 2019 年 11 月 14 日
Commented: Star Strider 2019 年 11 月 15 日
Hello,
I'm trying to solve this equation system but it runs indefinitely.
Symbols a and b are just parameters, the variables I want to solve for and x1,x2,x3,x4,x5
Do you have any idea about how I could make it?
I have tried fsolve without success.
Thanks in advance for you help.
clear clc
syms x1 x2 x3 x4 x5
syms a1 a2 a3 a4 a5 b1 b2
eqns = [x1*cos(a1+x2) - b1 == 0,
x1*cos(x5+x3) - a3*cos(x5) == 0,
x1*cos(a2+x4) - b2 == 0,
cos(x2) - a4*cos(x4) == 0,
cos(x3) - a5*cos(x4) == 0];
S= solve(eqns,[x5,x1,x2,x3,x4])

  0 件のコメント

サインイン to comment.

件の回答 (3)

Star Strider
Star Strider 2019 年 11 月 14 日
The Symbolic Math Toolbox is not optimal for such problems. It is likely not worth the effort to see if a symbolic solution exists, anyway.
It would be best to supply values for the ‘a’ and ‘b’ values, then use fsolve:
syms x1 x2 x3 x4 x5
syms a1 a2 a3 a4 a5 b1 b2
eqns = [x1*cos(a1+x2) - b1,
x1*cos(x5+x3) - a3*cos(x5),
x1*cos(a2+x4) - b2,
cos(x2) - a4*cos(x4),
cos(x3) - a5*cos(x4)];
eqns_fcn = matlabFunction(eqns, 'Vars',{[x1,x2,x3,x4,x5], a1, a2, a3, a4, a5, b1, b2}) % Create Anonymous Function
x0 = rand(5,1); % Initial Parameter Estimates
xparms = fsolve(@(in1)eqns_fcn(in1,a1,a2,a3,a4,a5,b1,b2), x0) % Use ‘fsolve’
The anonymous function is:
eqns_fcn = @(in1,a1,a2,a3,a4,a5,b1,b2)[-b1+in1(:,1).*cos(a1+in1(:,2));in1(:,1).*cos(in1(:,3)+in1(:,5))-a3.*cos(in1(:,5));-b2+in1(:,1).*cos(a2+in1(:,4));cos(in1(:,2))-a4.*cos(in1(:,4));cos(in1(:,3))-a5.*cos(in1(:,4))];
The ‘in1’ vector is in order: [x1,x2,x3,x4,x5].

  0 件のコメント

サインイン to comment.


John D'Errico
John D'Errico 2019 年 11 月 14 日
編集済み: John D'Errico 2019 年 11 月 14 日
I would reduce this to a 2 variable problem first.
That is, use equation 1 to solve for x1.
x1 = b1/cos(a1 + x2)
Likewise, isolate x2 and x3, using equations 4 and 5.
x2 = acos(a4*cos(x4)) + n2*2*pi
x3 = acos(a5*cos(x4)) + n3*2*pi
Here n2 and n3 are arbitrary integer constants. They allow us to recognize that if any solution exists, there will be infinitely many solutions, separated by arbitrary integer multiples of 2*pi for x2 and x3.
Given that, we can replace x1, x2, and x3 into equations 2 and 3. When you do that, you will find two equations in two unknowns.
First, look at equation 3, when we do that. I get this:
b1*cos(a2+x4) - b2*cos(a1 + acos(a4*cos(x4)) + n2*2*pi) == 0
Do you see that it is a problem in one unknown only? That is, x4 is the only unknown. I doubt it has an analytical solution. Regardless, if the parameters b1, b2, a1, a2, a4 are set to fixed real values, then you can solve for x4. Once you have x4, then you will recover the values of x2 and x3. Given x2, you get x1.
Finally, given x1,x2,x3,x4, you use equation 2 to recover the possible values for x5. Again, x5 will have infinitely many possible solutions.
Does this work? I'll try a symbolic solution. I'll arbitrarily set n2=0.
n2 = 0;
syms x1 x2 x3 x4 x5
syms b1 b2 a1 a2 a4
solve( b1*cos(a2+x4) - b2*cos(a1 + acos(a4*cos(x4)) + n2*2*pi) == 0,x4)
ans =
-log(-((exp(-a2*1i)*(- b2^2*exp(a2*1i) + b2*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - b2*exp(a1*2i)*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - 2*b1^2*exp(a1*2i)*exp(a2*1i) + 2*b2^2*exp(a1*2i)*exp(a2*1i) - b2^2*exp(a2*1i)*exp(a1*4i) - 2*a4^2*b2^2*exp(a1*2i)*exp(a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i + a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i + a2*1i)))/(2*(b1^2*exp(a1*2i + a2*2i) + a4^2*b2^2*exp(a1*2i) - a4*b1*b2*exp(a1*1i + a2*1i) - a4*b1*b2*exp(a1*3i + a2*1i))))^(1/2))*1i
-log(-((exp(-a2*1i)*(- b2^2*exp(a2*1i) - b2*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) + b2*exp(a1*2i)*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - 2*b1^2*exp(a1*2i)*exp(a2*1i) + 2*b2^2*exp(a1*2i)*exp(a2*1i) - b2^2*exp(a2*1i)*exp(a1*4i) - 2*a4^2*b2^2*exp(a1*2i)*exp(a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i + a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i + a2*1i)))/(2*(b1^2*exp(a1*2i + a2*2i) + a4^2*b2^2*exp(a1*2i) - a4*b1*b2*exp(a1*1i + a2*1i) - a4*b1*b2*exp(a1*3i + a2*1i))))^(1/2))*1i
-log(((exp(-a2*1i)*(- b2^2*exp(a2*1i) + b2*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - b2*exp(a1*2i)*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - 2*b1^2*exp(a1*2i)*exp(a2*1i) + 2*b2^2*exp(a1*2i)*exp(a2*1i) - b2^2*exp(a2*1i)*exp(a1*4i) - 2*a4^2*b2^2*exp(a1*2i)*exp(a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i + a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i + a2*1i)))/(2*(b1^2*exp(a1*2i + a2*2i) + a4^2*b2^2*exp(a1*2i) - a4*b1*b2*exp(a1*1i + a2*1i) - a4*b1*b2*exp(a1*3i + a2*1i))))^(1/2))*1i
-log(((exp(-a2*1i)*(- b2^2*exp(a2*1i) - b2*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) + b2*exp(a1*2i)*(b2^2*exp(a2*2i) + a4^2*b1^2*exp(a1*2i) + 4*b1^2*exp(a1*2i)*exp(a2*2i) - 2*b2^2*exp(a1*2i)*exp(a2*2i) + b2^2*exp(a2*2i)*exp(a1*4i) - 2*a4^2*b1^2*exp(a1*2i)*exp(a2*2i) + 4*a4^2*b2^2*exp(a1*2i)*exp(a2*2i) + a4^2*b1^2*exp(a1*2i)*exp(a2*4i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*1i) - 2*a4*b1*b2*exp(a1*1i)*exp(a2*3i) - 2*a4*b1*b2*exp(a2*1i)*exp(a1*3i) - 2*a4*b1*b2*exp(a1*3i)*exp(a2*3i))^(1/2) - 2*b1^2*exp(a1*2i)*exp(a2*1i) + 2*b2^2*exp(a1*2i)*exp(a2*1i) - b2^2*exp(a2*1i)*exp(a1*4i) - 2*a4^2*b2^2*exp(a1*2i)*exp(a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*1i + a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i - a2*1i) + a4*b1*b2*exp(a2*1i)*exp(a1*3i + a2*1i)))/(2*(b1^2*exp(a1*2i + a2*2i) + a4^2*b2^2*exp(a1*2i) - a4*b1*b2*exp(a1*1i + a2*1i) - a4*b1*b2*exp(a1*3i + a2*1i))))^(1/2))*1i
So solve finds 4 distinct solutions, some of which may be complex. That completely depends on the parameter values for a and b. If you know the values of a and b, that would help considerably, reducing the problem to something potentially managable. For example,
[b1 b2 a1 a2 a4] = deal(1,1,2,1.5,3);
x4 = solve( b1*cos(a2+x4) - b2*cos(a1 + acos(a4*cos(x4)) + n2*2*pi) == 0,x4)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
> In solve (line 304)
x4 =
1.4819196670462050035022873364136
So solve did not find an analytival solution, but it is a real value. As I said above, now you can recover the other 4 unknowns. And there will be infinitely many such solutions.

  0 件のコメント

サインイン to comment.


dd hh
dd hh 2019 年 11 月 15 日
Hello,
Thank you so much for your help.
I will study in details your answers because i'm not used to MATLAB and get back to you with the solution chosen.
Best Regards
David

  1 件のコメント

Star Strider
Star Strider 2019 年 11 月 15 日
@dd hh — Note that with trigonometric functions, the result will depend on the initial parameter estimates.

サインイン to comment.

サインイン してこの質問に回答します。


Translated by