using fsolve to solve non-linear equations in matlab

$\begingroup$

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

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.

Can someone please help me?

Thank you.

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

$\endgroup$ 1

1 Answer

$\begingroup$

It's not clear what the problem is without being given the error, but:

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];
x0=[1;1];
fsolve(F,x0)

worked for me. You can do this using "function F = ..." syntax, but then you need to write @F in the call to fsolve.

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like