solution of 3d nonlinear equation

x_p, y_p, z_p=(4, 5, 2)
x_1, y_1, z_1=(8, 9, 5)
x_2, y_2, z_2=(2, 5, 1)
x_3, y_3, z_3=(6, 1, 3)
t_1=5.692820*10^-9
t_2=-2.924173*10^-9
t_3=-12.010097*10^-9
c=3.0*10^8
and my three equations are
eqn1 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_1)^2+(y(s)-y_1)^2+(z(s)-z_2)^2)-(c*t_1)
eqn2 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_2)^2+(y(s)-y_2)^2+(z(s)-z_2)^2)-(c*t_1)
eqn3 = sqrt((x(s)-x_p)^2+(y(s)-y_p)^2+(z(s)-z_p)^2)-sqrt((x(s)-x_3)^2+(y(s)-y_3)^2+(z(s)-z_3)^2)-(c*t_1)
where only x(s), y(s), z(s) are unknown are rest all are known
BEST REGARDS

1 Comment

Perhaps the first equation should involve t1 instead of t_1, and second equation should involve t2 instead of t_1, and the third should involve t3 instead of t_1 ? You do not use t1, t2, or t3 after you define them.

Sign in to comment.

 Accepted Answer

x_p = 4; y_p = 5; z_p = 2;
x_1 = 8; y_1 = 9; z_1 = 5;
x_2 = 2; y_2 = 5; z_2 = 1;
x_3 = 6; y_3 = 1; z_3 = 3;
t1 = 5.692820*10^-9;
t2 = -2.924173*10^-9;
t3 = -12.010097*10^-9;
syms xs ys zs %our unknowns
syms c %constant not given in question
eqn1 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_1)^2+(ys-y_1)^2+(zs-z_2)^2)-(c*t1);
eqn2 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_2)^2+(ys-y_2)^2+(zs-z_2)^2)-(c*t2);
eqn3 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_3)^2+(ys-y_3)^2+(zs-z_3)^2)-(c*t3);
sol = solve([eqn1, eqn2, eqn3], [xs, ys, zs]);
disp(sol.xs)
disp(sol.ys)
disp(sol.zs)
the values will be parameterized in c, which you indicate is a known value, but which you did not provide a value for.
There are two solutions for each variable.
You should probably re-substitute the solutions and verify that the values work, as MATLAB warns that some of the solutions produced might no be true solutions.

12 Comments

i have placed the value of c but it is showing error
what is the error message?
Which MATLAB release are you using? I tried it on R2020a and R2020b, and it works fine. On R2020b, it gives a warning that "Possibly spurious solutions".
First of all, you used a vector of values in place of one of the constants. The vector was probably two elements long. For example you might have c as a vector of two values. That would have expanded the three equations into six equations.
When you use solve() with a vector of equations, MATLAB tries to find values of the variables that satisfy all of the equations at the same time. You cannot do something like
eqn = [x^2 + y == c, x - y^2 == 2*c];
solve( subs(eqn, c, [5 6]) )
and expect to get out a solution for one set of solutions for c == 5 and another set of solutions for c == 6. If you want to solve a system of equations while varying a parameter, then you should solve() with each of the values of the variable used in turn.
Secondly, the only way that the system I set up for you could have had 4 variables was if either you left c in place instead of substituting a constant, or else what you substituted for c itself had an unresolved variable in it.
I suspect the error about cell syntax and so on has to do with the fact that it did not find a solution.
Please post your exact current code.
https://www.mathworks.com/matlabcentral/answers/601690-solution-of-3d-nonlinear-equation#comment_1029733
x_p = 4; y_p = 5; z_p = 2;
x_1 = 8; y_1 = 9; z_1 = 5;
x_2 = 2; y_2 = 5; z_2 = 1;
x_3 = 6; y_3 = 1; z_3 = 3;
t1 = 5.692820*10^-9;
t2 = -2.924173*10^-9;
t3 = -12.010097*10^-9;
c=3.00*10^8
syms xs ys zs %our unknowns
eqn1 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_1)^2+(ys-y_1)^2+(zs-z_2)^2)-(c*t1);
eqn2 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_2)^2+(ys-y_2)^2+(zs-z_2)^2)-(c*t2);
eqn3 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_3)^2+(ys-y_3)^2+(zs-z_3)^2)-(c*t3);
sol = solve([eqn1, eqn2, eqn3], [xs, ys, zs]);
disp(sol.xs)
disp(sol.ys)
disp(sol.zs)
Works for me in R2015a. I do not have R2014a handy at the moment.
Installing R2014a is getting to be a distinct nuisance. R2014a does not work with an operating system as new as mine. I created some virtual machines for operating system versions old enough that they supported R2014a, and I installed two different operating systems and as well a third that I had an existing virtual machine for -- but the MATLAB installer would not run on any of them, due to some kind of Java problems...
I would have to install an old operating system onto a hard drive partition in order to install R2014a.... unless I can manage to get it running on one of my old Windows virtual machines.
ali hassan
ali hassan on 30 Sep 2020
Edited: ali hassan on 30 Sep 2020
THANKYOU SO MUCH SIR. i ran the code on matlab 2019 and i have done some tweaks and i am getting the solution but i want to filter my solution
this is a set of possible solutions i get from my code.but i only need three values but i get 6 possible solutions.i know that my solution can neither be negative nor it can be complex and it should show only accepted answer after ignoring other solution
there are 6 possible solutions but only three are right. now how to use loop maybe to ignore left entries as it is negative and it should only display right entries as solution
CODE:
x_p = 4; y_p = 5; z_p = 2;
x_1 = 8; y_1 = 9; z_1 = 5;
x_2 = 2; y_2 = 5; z_2 = 1;
x_3 = 6; y_3 = 1; z_3 = 3;
c=3.0*10^8;
t1 = 5.692820*10^-9;
t2 = -2.924173*10^-9;
t3 = -12.010097*10^-9;
syms xs ys zs %our unknowns
eqn1 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_1)^2+(ys-y_1)^2+(zs-z_2)^2)-(c*t1);
eqn2 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_2)^2+(ys-y_2)^2+(zs-z_2)^2)-(c*t2);
eqn3 = sqrt((xs-x_p)^2+(ys-y_p)^2+(zs-z_p)^2)-sqrt((xs-x_3)^2+(ys-y_3)^2+(zs-z_3)^2)-(c*t3);
sol = solve([eqn1, eqn2, eqn3], [xs ys zs]);
m = 1;
for n = 1:length(sol.xs)
possibleSol(1,m) = double(sol.xs(n));
possibleSol(2,m) = double(sol.ys(n));
possibleSol(3,m) = double(sol.zs(n));
m= m+1;
end
That is not 6 possible solutions, that is two solutions with three components each.
possibleSol(:, all(possibleSol>0 & imag(possibleSol)==0, 1))

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!