Thread Subject:
Solving two nonlinear equations with two unknowns in MATLAB

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Bilal

Date: 24 Jul, 2012 02:33:59

Message: 1 of 10

Hi,
I have two non-linear equations with two unknowns, i.e., tau and p. both equations are:
p=1-(1-tau).^(n-1)
and
tau = 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m)).

I am interested to find the value of tau.
After doing some research on internet I came to know that these equations can be solved by finding roots and finding fixed points. However, the problem is not that straight as it involves two non-linear equations, as opposed to various examples I found on internet which involves only one non-linear equation.
Additionally, I have matlab code for solving this problem, but still spending few days to understand and searching internet relentlessly, I couldn't understand how this solution actually works. Below I am giving that matlab code and need your helping hand to explain it to me the actual logic behind solving 'set of non-linear equations.

Matlab M-file is:

function result=tau_eq(tau)

n=6;
W=32;
m=5;

p=1-(1-tau).^(n-1);
result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));

Statement at the command window:
result=fzero(@tau_eq,[0,1],[])
result =

0.0448

The given result is right, however I do not understand the logic behind it. Particularly, the last equation in M-file confuses me, e.g., result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));. Any explanation or referring to useful resources will be highly appreciated.
--
Bilal

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Sargondjani

Date: 24 Jul, 2012 05:56:09

Message: 2 of 10

'result' is the function value that fzero tries to equalize to zero: tau=f(p) => tau-f(p)=0. that's it.

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Bilal

Date: 24 Jul, 2012 13:50:31

Message: 3 of 10

On Tuesday, July 24, 2012 2:56:09 PM UTC+9, Sargondjani wrote:
> 'result' is the function value that fzero tries to equalize to zero: tau=f(p) => tau-f(p)=0. that's it.

Thank you for your reply. but it is still confusing for me. I have a problem with more than two nonlinear equations which I have to solve, but before I write matlab code for that I have to understand the above problem very well.
Could you please explain it a little more as I am new to matlab.
cheers
--
bilal

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Torsten

Date: 24 Jul, 2012 14:11:01

Message: 4 of 10

On 24 Jul., 15:50, Bilal <bilalci...@googlemail.com> wrote:
> On Tuesday, July 24, 2012 2:56:09 PM UTC+9, Sargondjani wrote:
> > 'result' is the function value that fzero tries to equalize to zero: tau=f(p) => tau-f(p)=0. that's it.
>
> Thank you for your reply. but it is still confusing for me. I have a problem with more than two nonlinear equations which I have to solve, but before I write matlab code for that I have to understand the above problem very well.
> Could you please explain it a little more as I am new to matlab.
> cheers
> --
> bilal

If you have more than one equation, you'll usually need MATLAB's
FSOLVE to find a solution.
Look at the two examples provided under
http://www.mathworks.de/help/toolbox/optim/ug/fsolve.html
to learn how to set up the call to FSOLVE and the function routine
where you provide the nonlinear system of equations.
Then try FSOLVE to solve your system from above and the complicated
system with more than two unknowns.

Best wishes
Torsten.

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Sargondjani

Date: 24 Jul, 2012 18:28:21

Message: 5 of 10

Bilal <bilalcisco@googlemail.com> wrote in message <6b7c9e55-05a1-4e0e-959a-4200d35ff2e0@googlegroups.com>...
> On Tuesday, July 24, 2012 2:56:09 PM UTC+9, Sargondjani wrote:
> > 'result' is the function value that fzero tries to equalize to zero: tau=f(p) => tau-f(p)=0. that's it.
>
> Thank you for your reply. but it is still confusing for me. I have a problem with more than two nonlinear equations which I have to solve, but before I write matlab code for that I have to understand the above problem very well.
> Could you please explain it a little more as I am new to matlab.
> cheers
> --
> bilal

the solver tries to find the solution "result=0" and does so by adjusting tau. i dont know what you dont understand about that. so pls be more specific... do you want to know how the algorithm works?

by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Sargondjani

Date: 24 Jul, 2012 18:31:28

Message: 6 of 10

> by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.

sorry i didnt mean 1-to1 mapping, but i meant that you can get an explicit expression of p in terms of tau

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Bilal

Date: 25 Jul, 2012 03:23:19

Message: 7 of 10

On Wednesday, July 25, 2012 3:31:28 AM UTC+9, Sargondjani wrote:
> > by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.
>
> sorry i didnt mean 1-to1 mapping, but i meant that you can get an explicit expression of p in terms of tau

Thanks Sargondjani and Torsten,
Finally, I understand it. Actually, the last statement result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m)); was a bit confusing for me. I thought function returns 'result' but it is ,in fact, returning 'tau' which is my required answer.
--

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Sargondjani

Date: 25 Jul, 2012 09:26:07

Message: 8 of 10

Bilal <bilalcisco@googlemail.com> wrote in message <247fe7fc-092a-40d6-95cb-e33cf42a8d59@googlegroups.com>...
> On Wednesday, July 25, 2012 3:31:28 AM UTC+9, Sargondjani wrote:
> > > by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.
> >
> > sorry i didnt mean 1-to1 mapping, but i meant that you can get an explicit expression of p in terms of tau
>
> Thanks Sargondjani and Torsten,
> Finally, I understand it. Actually, the last statement result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m)); was a bit confusing for me. I thought function returns 'result' but it is ,in fact, returning 'tau' which is my required answer.
> --

well not exactly. the function returns the value for 'return'. and solve tries to set this value to 0. when return = 0 your system is solved... so it is solve that returns 'tau' as the solution to 'return = 0'

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Neeraj

Date: 6 Aug, 2012 06:37:14

Message: 9 of 10

as far as equation written by Mr. Bilal is concerned they are giving correct results however there is an syntatically another method of writing the secong function which is also giving the correct answer the code for two function is given as unedr

function result=tau_eq(tau) %bilal function

n=6;
W=32;
m=5;
tau

p=1-(1-tau).^(n-1);
result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));

function result=tau_eq(tau) //function written by me

n=6;
W=32;
m=5;
tau

p=1-(1-tau).^(n-1);
result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));

As one can see there is syntactically difference between two function although the results are same.
my first challenge is to understand the understand this syntax difference as I am ew to matlab. Moreover i have another code for some other equations like

function result=chatzim(tau)

n=6;
W=32;
m=5;

p=1- power((1-tau),(n-1));
A =(1 - p)* W.*(1 - power((2 * p), m+1)) ;
B =(1 - 2* p).*(1 - power(p, m+1));
C =1 - power(p, m+1);
D =(2 *(1-2* p) ./ (A + B )).* C;
result=tau - D;

at command prompt
result=fzero(@chatzim,[0, 1], [ ])

the above function is returning the values from 0 to 0.99 (individually). The function fails once the input value is 1. Is this due to syntax error for what

Neeraj

"Sargondjani" wrote in message <juoe3f$2pr$1@newscl01ah.mathworks.com>...
> Bilal <bilalcisco@googlemail.com> wrote in message <247fe7fc-092a-40d6-95cb-e33cf42a8d59@googlegroups.com>...
> > On Wednesday, July 25, 2012 3:31:28 AM UTC+9, Sargondjani wrote:
> > > > by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.
> > >
> > > sorry i didnt mean 1-to1 mapping, but i meant that you can get an explicit expression of p in terms of tau
> >
> > Thanks Sargondjani and Torsten,
> > Finally, I understand it. Actually, the last statement result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m)); was a bit confusing for me. I thought function returns 'result' but it is ,in fact, returning 'tau' which is my required answer.
> > --
>
> well not exactly. the function returns the value for 'return'. and solve tries to set this value to 0. when return = 0 your system is solved... so it is solve that returns 'tau' as the solution to 'return = 0'

Subject: Solving two nonlinear equations with two unknowns in MATLAB

From: Bilal

Date: 6 Aug, 2012 17:21:46

Message: 10 of 10

Neeraj,
I have same question. Furthermore when i draw 'p vs tau' curve there is fluctuation which in fact should be smooth.
I am also new to matlab and also to solving nonlinear equations, would be thankful if someone elaborate it.
--
Bilal

On Monday, August 6, 2012 3:37:14 PM UTC+9, Neeraj wrote:
> as far as equation written by Mr. Bilal is concerned they are giving correct results however there is an syntatically another method of writing the secong function which is also giving the correct answer the code for two function is given as unedr
>
>
>
> function result=tau_eq(tau) %bilal function
>
>
>
> n=6;
>
> W=32;
>
> m=5;
>
> tau
>
>
>
> p=1-(1-tau).^(n-1);
>
> result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));
>
>
>
> function result=tau_eq(tau) //function written by me
>
>
>
> n=6;
>
> W=32;
>
> m=5;
>
> tau
>
>
>
> p=1-(1-tau).^(n-1);
>
> result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m));
>
>
>
> As one can see there is syntactically difference between two function although the results are same.
>
> my first challenge is to understand the understand this syntax difference as I am ew to matlab. Moreover i have another code for some other equations like
>
>
>
> function result=chatzim(tau)
>
>
>
> n=6;
>
> W=32;
>
> m=5;
>
>
>
> p=1- power((1-tau),(n-1));
>
> A =(1 - p)* W.*(1 - power((2 * p), m+1)) ;
>
> B =(1 - 2* p).*(1 - power(p, m+1));
>
> C =1 - power(p, m+1);
>
> D =(2 *(1-2* p) ./ (A + B )).* C;
>
> result=tau - D;
>
>
>
> at command prompt
>
> result=fzero(@chatzim,[0, 1], [ ])
>
>
>
> the above function is returning the values from 0 to 0.99 (individually). The function fails once the input value is 1. Is this due to syntax error for what
>
>
>
> Neeraj
>
>
>
> "Sargondjani" wrote in message <juoe3f$2pr$1@newscl01ah.mathworks.com>...
>
> > Bilal <bilalcisco@googlemail.com> wrote in message <247fe7fc-092a-40d6-95cb-e33cf42a8d59@googlegroups.com>...
>
> > > On Wednesday, July 25, 2012 3:31:28 AM UTC+9, Sargondjani wrote:
>
> > > > > by the way, to me it seems there is a one-to-one mapping between p and tau,which would make it a one variable problem... which shouldnt be to difficult for any solver to analyze.
>
> > > >
>
> > > > sorry i didnt mean 1-to1 mapping, but i meant that you can get an explicit expression of p in terms of tau
>
> > >
>
> > > Thanks Sargondjani and Torsten,
>
> > > Finally, I understand it. Actually, the last statement result=tau - 2*(1-2*p) ./ ( (1-2*p)*(W+1)+(p*W).*(1-(2*p).^m)); was a bit confusing for me. I thought function returns 'result' but it is ,in fact, returning 'tau' which is my required answer.
>
> > > --
>
> >
>
> > well not exactly. the function returns the value for 'return'. and solve tries to set this value to 0. when return = 0 your system is solved... so it is solve that returns 'tau' as the solution to 'return = 0'

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us