Path: news.mathworks.com!not-for-mail From: "Miroslav Balda" <miroslav.nospam@balda.cz> 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$1@fred.mathworks.com> References: <ib6utf$ldq$1@fred.mathworks.com> <ib6vnn$dps$1@fred.mathworks.com> Reply-To: "Miroslav Balda" <miroslav.nospam@balda.cz> NNTP-Posting-Host: webapp-02-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1289167264 1685 172.30.248.37 (7 Nov 2010 22:01:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 7 Nov 2010 22:01:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 360709 Xref: news.mathworks.com comp.soft-sys.matlab:684535 "Leo " <leoj_cruzz@hotmail.com> wrote in message <ib6vnn$dps$1@fred.mathworks.com>... > "Leo " <leoj_cruzz@hotmail.com> wrote in message <ib6utf$ldq$1@fred.mathworks.com>... > > 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: www.mathworks.com/matlabcentral/fileexchange/17534 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. Mira