# using fsolve to solve non-linear equations in matlab

I'm trying to solve this system equations in matlab

syms  y z i
x=[29.6,29.4,34.4,35.1,34.3,36.1,31.6,32.9,31.5,28.3,37.1,28.4,27.3,33.1,31.3,33.1]
n = 16
eqns = sym(zeros(1, 2 * n));

for i = 1:n
a = 0;
for j = 1:i
a = a + exp(-((x(j) - y) / z));
end
a = i/z - a/z;
eqns(i) = a == 0;
end

for i = 1:n
a = 0;
for j = 1:i
a = a + ((x(j) - y)/z^2) - ((x(i) - y)/z^2) * exp((-x(j) + y)/z);
end
a = -i/z + a;
eqns(i + 16) = a == 0;
end
eqns
solve(eqns, [y, z])


But it seems solve can't solve this one.

Warning: Cannot find explicit solution.
> In solve (line 316)
In xx (line 24)


I tried to use fslove but by follow the tutorial at https://www.mathworks.com/help/optim/ug/fsolve.html?s_tid=gn_loc_drop

but when I tried to enter

function F = root2d(x)

F(1) = exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - 0.5;


matlab throw error.

Thank you.

P/S: Can this problem be solved with singular?I'm trying to solve this system equations in matlab

• Your fsolve code doesn't match the system of 32 equations you're trying to solve symbolically. It's not clear what you're trying to do. I'm also not sure why you're using i as a symbolic variable and the re-defining it in your for loops. – horchler Mar 8 '17 at 19:59

F=@(x) [exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);x(1)*cos(x(2)) + x(2)*sin(x(1)) - 0.5];