MATLAB: I am trying to solve for x; but I am getting an error. With a linear system of equations this works. I would appreciate your suggestions. Thanks

nonlinear system of equations

clear all G = [1 2 3]; F=[1 2 3]; syms x y for j=1:1:3 a(j)=F(j)+(G(j)).^2*(1-x)^2; xsoln(j) = solve(a(j),x); end

Best Answer

Store the loop results as a cell array:
G = [1 2 3];
F=[1 2 3];
syms x y
for j=1:1:3
a(j)=F(j)+(G(j)).^2*(1-x)^2;
xsoln{j} = solve(a(j),x);
end
celldisp(xsoln)
xsoln{1} =
1 - 1i
1 + 1i
xsoln{2} =
1 - (2^(1/2)*1i)/2
(2^(1/2)*1i)/2 + 1
xsoln{3} =
1 - (3^(1/2)*1i)/3
(3^(1/2)*1i)/3 + 1
Another option if you don’t want symbolic results is to use vpasolve instead of solve.