简体   繁体   中英

Error while solving system of non-linear equations in MATLAB

I am trying to solve system of non-linear equation simultaneously on MATLAB. I am getting the error:

Comma separated list expansion has cell syntax for an array that is not a cell".

The screenshot of the error is attached:

错误

My code is given below:

syms x y z T
x1=1;
x2=1;
x3=1;
x4=1;
y1=1;
y2=1;
y3=1;
y4=1;
z1=1;
z2=1;
z3=1;
z4=1;
c=1;
t1=1;
t21=1;
t31=1;
t41=1;
eq1 = ((x1 - x)^2 + (y1 - y)^2 + (z1 - z)^2 )^1/2 - (c * t1) + (c * T)==0;
eq2 = ((x2 - x)^2 + (y2 - y)^2 + (z2 - z)^2 )^1/2 - (c * t21) - (c*t1) + (c*T)==0;
eq3 = ((x3 - x)^2 + (y3 - y)^2 + (z3 - z)^2 )^1/2 - (c * t31) - (c*t1) + (c*T)==0;
eq4 = ((x4 - x)^2 + (y4 - y)^2 + (z4 - z)^2 )^1/2 - (c * t41) - (c*t1) + (c*T)==0;
sol = solve(eq1, eq2, eq3, eq4);
xSol = sol.x
ySol = sol.y
zSol = sol.z
TSol = sol.T

When I run your code, there is no error in my MATLAB 2020a.

However it returns an empty solution. This is normal, your equations are not solvable. Check eq1 and eq2 . For your values, they are:

eq1 = ((1 - x)^2 + (1- y)^2 + (1 - z)^2 )^1/2 - (1) + (1 * T)==0;
eq2 = ((1 - x)^2 + (1- y)^2 + (1 - z)^2 )^1/2 - (2) + (1 * T)==0;

This has of course no solution,as you are basically saying:

eq1= ((1 - x)^2 + (1- y)^2 + (1 - z)^2 )^1/2 + (1 * T)==1
eq2= ((1 - x)^2 + (1- y)^2 + (1 - z)^2 )^1/2 + (1 * T)==2

Both can not coexist.

It is possible that you are using an older version of MATLAB that throws warning when solution does not exist and does not allow you to read it later, where your error happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM