Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Equation solver

Subject: Equation solver

From: Leo

Date: 7 Nov, 2010 19:33:04

Message: 1 of 7

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

Subject: Equation solver

From: Leo

Date: 7 Nov, 2010 19:47:03

Message: 2 of 7

"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

Subject: Equation solver

From: Miroslav Balda

Date: 7 Nov, 2010 22:01:04

Message: 3 of 7

"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

Subject: Equation solver

From: Steven_Lord

Date: 7 Nov, 2010 22:44:49

Message: 4 of 7



"Leo " <leoj_cruzz@hotmail.com> wrote in message
news: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?

Use the FZERO function.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Equation solver

From: Leo

Date: 8 Nov, 2010 00:07:03

Message: 5 of 7

"Steven_Lord" <slord@mathworks.com> wrote in message <ib7a51$cfu$1@fred.mathworks.com>...
>
>
> "Leo " <leoj_cruzz@hotmail.com> wrote in message
> news: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?
>
> Use the FZERO function.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com
Thank you.

The equation has multiple solutions. Is there a way all solutions are shown?

Subject: Equation solver

From: Steven_Lord

Date: 8 Nov, 2010 03:40:28

Message: 6 of 7



"Leo " <leoj_cruzz@hotmail.com> wrote in message
news:ib7ev7$ft3$1@fred.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ib7a51$cfu$1@fred.mathworks.com>...

*snip*

> The equation has multiple solutions. Is there a way all solutions are
> shown?

No. There's not even a really good (theoretical) way I'm aware of to
determine _how many_ solutions an arbitrary equation has, much less what
they all are.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Equation solver

From: Roger Stafford

Date: 8 Nov, 2010 07:22:04

Message: 7 of 7

"Leo " <leoj_cruzz@hotmail.com> wrote in message <ib7ev7$ft3$1@fred.mathworks.com>...
> "Steven_Lord" <slord@mathworks.com> wrote in message <ib7a51$cfu$1@fred.mathworks.com>...
> > "Leo " <leoj_cruzz@hotmail.com> wrote in message
> > news:ib6utf$ldq$1@fred.mathworks.com...
> > > I have the following equation:
> > > i = a*(z - s*log(1 + z/s))*(1 + s/z)
> > Use the FZERO function.
> The equation has multiple solutions. Is there a way all solutions are shown?
- - - - - - - - - -
  The three parameters in your equation can be reduced to a single parameter if you define w = 1+z/s and k = i/a/s. The equation then becomes much simpler:

 (w-1)*(w-k) - w*log(w) = 0

This is the difference between a second degree polynomial in w with zeros at 1 and k, and the expression w*log(w) which has zeros at 0 and 1.

  It should be comparatively easy to use fzero on this function to find w given k. As you can see, it always has a root at w = 1, (though that would require the factor 1+s/z in the original equation to be infinite.) If k is positive, there will be a second root for w > 1. When k = 0, this root coalesces with the w = 1 root but another root then appears at w = 0. For 0 > k >= -0.2162166, these two roots approach each other at the point w = 0.316197 (approx.) and become a single root there as k approaches the lower limit. For k more negative that this, both roots suddenly vanish and w = 1 remains as the only root.

  As Steve says, you can use fzero to determine these roots precisely for each value of k you select. To handle the multiple roots you should use the two-element vector form of "x0" in the second argument to bracket the value w on either side of the root you are seeking. The above discussion should aid you in choosing the limits in x0 appropriately for the various values of k.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us