MATLAB Answers

0

solving 4 nonlinear equations with 4 variables

Asked by Mohamad Nour Alkilani on 14 Oct 2018
Latest activity Commented on by Stephan
on 14 Oct 2018
Hi there,
I am attempting to solve 4 nonlinear equations with 4 variables
I have x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,v,t1,t2,t3,t4
(x0-x1)^2+(y0-y1)^2+(z0-z1)^2-(v*T0)^2-2*(v*T0*v*t1)-(v*t1)^2=0
(x0-x2)^2+(y0-y2)^2+(z0-z2)^2-(v*T0)^2-2*(v*T0*v*t2)-(v*t2)^2=0
(x0-x3)^2+(y0-y3)^2+(z0-z3)^2-(v*T0)^2-2*(v*T0*v*t3)-(v*t3)^2=0
(x0-x4)^2+(y0-y3)^2+(z0-z4)^2-(v*T0)^2-2*(v*T0*v*t4)-(v*t4)^2=0
I need to get x0,y0,z0, and T0.
could you please help me in clarifying the appropriate method.
thanks.

  1 Comment

Is y3 correct in equation 4?:
(x0-x4)^2+(y0-y3)^2+(z0-z4)^2-(v*T0)^2-2*(v*T0*v*t4)-(v*t4)^2=0
I suspect it should be y4.

Sign in to comment.

Tags

Products

1 Answer

Answer by Stephan
on 14 Oct 2018
Edited by Stephan
on 14 Oct 2018

Hi,
have a look at fsolve to solve this numerically.
Here is an example for your case with some fantasy values:
solve_nonlinear_system
function solve_nonlinear_system
% Insert your known values here - fantasy values for showing how to use fsolve:
x1 = 12;
y1 = 15;
z1 = 10;
x2 = 20;
y2 = 25;
z2 = 22;
x3 = 38;
y3 = 41;
z3 = 37;
x4 = 62;
y4 = 62;
z4 = 58;
v = 15;
t1 = 10;
t2 = 40;
t3 = 65;
t4 = 10;
% Initial solution for fsolve:
x_init = [1 1 1 1];
% call fsolve:
sol = fsolve(@system_equations,x_init);
% show results:
fprintf('x0 = %.5f,\ny0 = %.5f,\nz0 = %.5f and\nT0 = %.5f\n', sol(1),sol(2),sol(3),sol(4))
% Your objective function:
function F = system_equations(x)
x0 = x(1);
y0 = x(2);
z0 = x(3);
T0 = x(4);
F = [(x0-x1)^2+(y0-y1)^2+(z0-z1)^2-(v*T0)^2-2*(v*T0*v*t1)-(v*t1)^2,...
(x0-x2)^2+(y0-y2)^2+(z0-z2)^2-(v*T0)^2-2*(v*T0*v*t2)-(v*t2)^2,...
(x0-x3)^2+(y0-y3)^2+(z0-z3)^2-(v*T0)^2-2*(v*T0*v*t3)-(v*t3)^2,...
(x0-x4)^2+(y0-y4)^2+(z0-z4)^2-(v*T0)^2-2*(v*T0*v*t4)-(v*t4)^2];
end
end
If you replace the values by yours it should work properly.
NOTE: I guess there is a typo i your 4th equation - i would expect it should be y4 not y3 in:
(x0-x4)^2+(y0-y3)^2+(z0-z4)^2-(v*T0)^2-2*(v*T0*v*t4)-(v*t4)^2=0
Best regards
Stephan

  0 Comments

Sign in to comment.