Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Solving a nonlinear system with fsolve
Replies: 2   Last Post: Apr 30, 2013 9:16 AM

 Messages: [ Previous | Next ]
 Tot Posts: 8 Registered: 4/25/13
Solving a nonlinear system with fsolve
Posted: Apr 30, 2013 8:53 AM

Hi,

I have a problem finding the right solution of a nonlinear system with fsolve.
I tried with 2 equations instead of n equations and I see that fsolve doesn't find the exact solution of the system.
Here is the equations :
------------------------------------------------------------
function F=test(T) % T is the unknown column (T(1),T(2))'

%Input values
n=2;
t0=8;
tstar=zeros(n,1);
C=zeros(n,1);
P=600;
mu=zeros(n,1);

C(1,1)=18;
C(2,1)=18;
mu(1,1)=1;
mu(2,1)=2;
tstar(1,1)=6;
tstar(2,1)=3;
S=sum(C)+P;

F(1,1)=C(1,1)-S*((exp((T(1)-tstar(1,1))/mu(1,1)))-(mu(2,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));

F(2,1)=C(2,1)-S*((exp((T(2)-tstar(2,1))/mu(2,1)))-(mu(1,1)/(mu(1,1)+mu(2,1)))*(exp((T(1)-tstar(1,1))/mu(1,1)))*(exp((T(2)-tstar(2,1))/mu(2,1))));

end
----------------------------------------------------------
Then I execute:

fsolve(@(T) test(T),[1;1])

and I find one correct value but the second is not right. This system can be solved easily : replace exp( (T1-tstar1)/mu1 ) by x1, the same thing for x2, then you solve the second degree polynomial equation exactly and you deduce T1 and T2.
The T2 value found by fsolve is always right but T1 is always wrong, except when all the parameters (mu, C, tstar) are the same both for 1 and 2. In this case, T1=T2.

Why doesn't fsolve give me the right solutions for a simple system of 2 equations? What algorithm should I use for this kind of system, knowing that I want to solve it for n equations?

Please don't hesitate if it is not clear.
Najib

Date Subject Author
4/30/13 Tot
4/30/13 Tot
4/30/13 Alan Weiss