0
$\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 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.

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$
  • $\begingroup$ 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. $\endgroup$ – horchler Mar 8 '17 at 19:59
0
$\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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.