I am trying to solve a system of non-linear equations in matlab. At first I tried with the solve and it did not work out. Now I'm trying with fsolve and it gives me incoherent results, in addition to stop in the second iteration. I pass the code, (basically it is the speed of regression along the length and time of a rocket):
%% parámetros
a = 2.07E-05; n = 0.75; m = 0.2; rho_O2 = 1180; L = 1: 30; mox = 0.030259;
%% initial variables
D0 (1: length (L)) = 0.01; x = (1: length (L)) 1E-2; mox0 (1: length (L)) = 0; for i = 1: length (L) A0 (i) = pi (D0 (i) / 2) ^ 2; S0 (i) = pi * D0 (i) * x (i); r0 (i) = 0; mf0 (i) = r0 (i) * S0 (i) * rho_O2; mT0 (i) = mf0 (i) + mox0 (i); rhoV0 (i) = mT0 (i) / A0 (i); OF0 (i) = mox0 (i) / mf0 (i); end D (1,:) = D0 '; A (1,:) = A0 '; S (1,:) = S0 '; r (1,:) = r0 '; mf (1,:) = mf0 '; mT (1,:) = mT0 '; rhoV (1,:) = rhoV0 '; OF (1,:) = OF0 ';
%% regression
x0 = [r0 mf0 mT0 rhoV0] for t = 2: 20 for i = 1: length (L) D (t, i) = D (t-1, i) + 2 * r (t-1, i); A (t, i) = pi * (D (t, i) / 2) ^ 2; S (t, i) = pi * D (t, i). * X (i); xx = [r mf mT rhoV]; F = @ (xx) [xx (1) - ((a / (x (i) ^ m)) * xx (4) ^ n); xx (2) - (xx (1) * S (t, i) * rho_O2); xx (3) - (xx (2) + mox); xx (2) - (xx (3) / A (t, i))]; options = optimset ('TolX', 1e-8); [xx, exitflag] = fsolve (F, x0, options);
I raised the tolerance to see if this worked. Thanks in advance.