Nonlinear multiple equations = fsolve?
Show older comments
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
Answers (3)
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];
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
on 22 Dec 2018
Edited: KALYAN ACHARJYA
on 22 Dec 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
on 22 Dec 2018
0 votes
3 Comments
madhan ravi
on 22 Dec 2018
what's your expected solution ? please clarify
Piotr Ogórek
on 22 Dec 2018
Edited: Piotr Ogórek
on 22 Dec 2018
Piotr Ogórek
on 22 Dec 2018
Categories
Find more on Structural Mechanics 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!