How to solve a non linear simultaneous equation with 4 unknowns and 4 equations ?

How to solve a non linear simultaneous equation with 4 unknowns and 4 equations ?
these are my equations:
% x^2 + y^2 + z^2 = (t^2)*(299792458^2)
% (A + x)^2 + (B + y)^2 + (C + z)^2 = ((q + t)^2 )*(299792458^2)
% (D + x)^2 + (E + y)^2 + (F + z)^2 = ((r + t)^2 )*(299792458^2)
% (G + x)^2 + (H + y)^2 + (I + z)^2 = ((s + t)^2 )*(299792458^2)
where x,y,z, and t are the unknowns and A,B,C,D,E,F,G,H,I,q,r and s are constants.
Any help on how best to go about solving this is appreciated.
-mk

Answers (1)

Use fsolve

4 Comments

Thanks for your answer. I have been trying out fsolve per your advice. I'm currently getting an error which i cant figure out.
Could i have missed something here? do excuse any novice mistakes :)
Do find the command window and script editor code below.
Thanks again and appreciate your help.
..................this is my command window ..........
>> x0= [-5 -5]
x0 =
-5 -5
>> fsolve(@myfun, x0) Undefined function or variable 't'.
Error in myfun (line 3) F = [- 89875517873681764*t^2 + x^2 + y^2 + z^2 ;
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
>> ........................this is my myfun.m code.............
function F = myfun(x)
F = [- 89875517873681764*t^2 + x^2 + y^2 + z^2 ;
(x + 1/5)^2 + (y + 1/5)^2 - 89875517873681764*(t + 1/1000000000)^2 + z^2 ;
(x + 1/2)^2 - 89875517873681764*(t + 7737125245533627/38685626227668133590597632)^2 + (z + 1/10)^2 + (- 89875517873681764*t^2 + x^2 + y^2 + y + z^2)^2 ;
(x + 3/5)^2 + (y + 3/5)^2 + (z + 1/10)^2 - 89875517873681764*(t + 785801782749509/604462909807314587353088)^2]
end
x shall be a vector with the 4 unknowns. Try :
function F = myfun(x)
F = [- 89875517873681764*x(4)^2 + x(1)^2 + x(2)^2 + x(3)^2 ;
(x(1) + 1/5)^2 + (x(2) + 1/5)^2 - 89875517873681764*(x(4) + 1/1000000000)^2 + x(3)^2 ;
(x(1) + 1/2)^2 - 89875517873681764*(x(4) + 7737125245533627/38685626227668133590597632)^2 + (x(3) + 1/10)^2 + (- 89875517873681764*x(4)^2 + x(1)^2 + x(2)^2 + x(2) + x(3)^2)^2 ;
(x(1) + 3/5)^2 + (x(2) + 3/5)^2 + (x(3) + 1/10)^2 - 89875517873681764*(x(4) + 785801782749509/604462909807314587353088)^2]
end
thanks for the help. I have replaced the unknowns to x(1),x(2), x(3), x(4) but now I have this error instead. Error shown below.
Based on the help file example i used x0 = [-5 -5]. If you could share some info on x0 would be very helpful
could there be something amiss here.
------------ERROR------------
>> x0 = [-5 -5]
x0 =
-5 -5
>> [x,fval] = fsolve(@myfun,x0) Attempted to access x(4); index out of bounds because numel(x)=2.
Error in myfun (line 3) F = [- 89875517873681764*x(4)^2 + x(1)^2 + x(2)^2 + x(3)^2 ;
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
I have also tried with x0 = [-5 ;-5 ; -5 ; -5]
it attempts to solve but I get this error at the end:
fsolve stopped because the relative size of the current step is less than the default value of the step size tolerance squared, but the vector of function values is not near zero as measured by the default value of the function tolerance.

Sign in to comment.

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Asked:

on 16 Mar 2013

Community Treasure Hunt

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

Start Hunting!