Nonlinear multiple equations = fsolve?

3 vues (au cours des 30 derniers jours)
Piotr Ogórek
Piotr Ogórek le 22 Déc 2018
Modifié(e) : Matt J le 23 Déc 2018
Hello,
I have a problem with finding a solution for multiple nonlinear equations. I tried using 2 different forms of the equations, but I get 2 different problems in each case.
1) first attempt - I only get the solution of [0;0;0] which is true to fulfill the equation, but there is/there are other solutions which i can't find.
2) second attempt - it doesn't find the solution with info:
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
default value of the function tolerance.
Here is the function.
function F = myfun(x,a,b,c,alfa,beta,gamma)
F= [
%first attempt
alfa*(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(a(1)^2+a(2)^2+a(3)^2))-((x(1)*a(1)+x(2)*a(2)+x(3)*a(3)));
beta*(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(b(1)^2+b(2)^2+b(3)^2))-((x(1)*b(1)+x(2)*b(2)+x(3)*b(3)));
gamma*(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(c(1)^2+c(2)^2+c(3)^2))-((x(1)*c(1)+x(2)*c(2)+x(3)*c(3)));
%second attempt
% alfa-((x(1)*a(1)+x(2)*a(2)+x(3)*a(3))/(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(a(1)^2+a(2)^2+a(3)^2)));
% beta-((x(1)*b(1)+x(2)*b(2)+x(3)*b(3))/(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(b(1)^2+b(2)^2+b(3)^2)));
% gamma-((x(1)*c(1)+x(2)*c(2)+x(3)*c(3))/(sqrt(x(1)^2+x(2)^2+x(3)^2)*sqrt(c(1)^2+c(2)^2+c(3)^2)));
];
And running it:
x0 = [10;10;10];
a=[0,1,1.73];
b=[0,1.73,1];
c=[-1,0,1.73];
alfa=0.8926;
beta=0.8183;
gamma=0.5603;
[out,fval] = fsolve(@(x) myfun(x,a,b,c,alfa,beta,gamma),x0)
In fact I try to solve such a problem:
I've got 3 vectors (in 3D) and 3 angles - in fact cosinus of them. This are angles between each of those vectors and other vector which i try to find.
Has anybody idea how to help me?
Regards,
Piotrek

Réponses (3)

Matt J
Matt J le 22 Déc 2018
Modifié(e) : Matt J le 23 Déc 2018
The problem is equivalent to the constrained least squares problem
where
A=[a/norm(a);b/norm(b);c/norm(c)];
d=[alfa;beta;gamma];
The solution can be found analytically using my trustregprob routine (Download)
x=trustregprob(A.'*A,A.'*d,1,1);
The solution I find has a slight 4% relative error, meaning there is no exact solution to the original problem, but that's likely because the input data alfa,beta,gamma,a,b,c was posted with only 4 decimal places precision.
>> x, relativeError=norm(A*x-d)/norm(d)
x =
0.3403
0.4507
0.8253
relativeError =
0.0392

KALYAN ACHARJYA
KALYAN ACHARJYA le 22 Déc 2018
Modifié(e) : KALYAN ACHARJYA le 22 Déc 2018
Is this the solution?
Equation solved.
fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient.
<stopping criteria details>
out =
1.0e-06 *
0.4311
0.1091
0.7377
fval =
1.0e-06 *
0.1510
0.4820
0.1193
>>

Piotr Ogórek
Piotr Ogórek le 22 Déc 2018
Yes, it is.
But the out ~=[0;0;0] doesn't satisfy me. I'm looking for another solution which exists.
  3 commentaires
Piotr Ogórek
Piotr Ogórek le 22 Déc 2018
Modifié(e) : Piotr Ogórek le 22 Déc 2018
okay, so for this parameters:
I would expect that the vector should be [1;2;3]
x0 = [10;10;10];
a = [2,3,1];
b = [0,2,1];
c = [1,0,1];
alfa=11/14;
beta=sqrt(7/10);
gamma=2/sqrt(7);
[out,fval] = fsolve(@(x) myfun(x,a,b,c,alfa,beta,gamma),x0)
Piotr Ogórek
Piotr Ogórek le 22 Déc 2018
Actually, all vectors with direction [1;2;3] or multiplied by a scalar fullfil the equations:
But how to find it?
myfun([1;2;3],a,b,c,alfa,beta,gamma)
ans =
0
0
0
>> myfun([10;20;30],a,b,c,alfa,beta,gamma)
ans =
0
0
0
>> myfun([20;40;60],a,b,c,alfa,beta,gamma)
ans =
0
0
0

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by