From: "Miroslav Balda" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Equation solver
Date: Sun, 7 Nov 2010 22:01:04 +0000 (UTC)
Organization: Miroslav Balda
Lines: 40
Message-ID: <ib77j0$1kl$>
References: <ib6utf$ldq$> <ib6vnn$dps$>
Reply-To: "Miroslav Balda" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1289167264 1685 (7 Nov 2010 22:01:04 GMT)
NNTP-Posting-Date: Sun, 7 Nov 2010 22:01:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 360709
Xref: comp.soft-sys.matlab:684535

"Leo " <> wrote in message <ib6vnn$dps$>...
> "Leo " <> wrote in message <ib6utf$ldq$>...
> > Hi,
> > 
> > I have the following equation:
> > i = a*(z - s*log(1 + z/s))*(1 + s/z)
> > 
> >  I want to assign numeric values to a, s, and i and find z (just as a hp calculator equation solver does).
> > 
> > I can input the values, but i have problems on how to solve and find z.
> > 
> > Furthermore, suppose there a a 100 values for each of the variables in excel spreadsheet. How can I substitute each value and obtain 100 values for z in the same spreadsheet?
> > 
> > Thanks in advance
> Also i can't solve for z (i.e. z = f(a, s, i). If i could i could directly enter the equation for z in excel

Hi Leo,

If you like to solve the problem in Excel, You have to ask somewhere else, not here. Should you like to solve it in MATLAB, there are more possibilities.
You can use some function from Optimization Toolbox or my function LMFnlsq from FEX:
For the solution, you have to write a function for evaluation residuals of the equation, say resid.m, that could have the following form:

function r = resid(p)
%  RESID   calculates a residual of an equation
a = p(1);
s = p(2);
i = p(3);
r = a*(z - s*log(1 + z/s))*(1 + s/z) - i;

The solution is found by calling
     [p,ssq,cnt] = LMFnlsq(resid,p0,'Display',-1) % if you wish to see iterations 

Parameter p0 is your estimate of the solution z. 
All 100 solutions can be obtained in the for cycle after reading your data [a,s,i] at once from the Excel file by calling a function xlsread.

Hope it helps.