       Re: Newton-Raphson Root Finding, Difficulty in coding

• To: mathgroup at smc.vnet.net
• Subject: [mg131817] Re: Newton-Raphson Root Finding, Difficulty in coding
• From: Bob Hanlon <hanlonr357 at gmail.com>
• Date: Wed, 9 Oct 2013 22:11:07 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20131009061159.57E046A24@smc.vnet.net>

```a = 1.36 // Rationalize[#, 0] &;
b = .003183 // Rationalize[#, 0] &;
R = .0820578 // Rationalize[#, 0] &;
T = 333;
inc = (592 - 39)/600;

v[atm_] :=
vi - ((((atm) + (a/vi^2)) (vi - b) - (R*T))/((atm) - (a/vi^2) + (2 a*
b/vi^3)));

Using Solve

data = {#, vi /. Solve[v[#] == 0, vi][[-1]]} & /@
Range[39/10, 592/10, inc];

ListLinePlot[data,
PlotRange -> All,
Frame -> True,
Axes -> False,
FrameLabel -> (Style[#, 16] & /@ {"atm", "vi"})]

Using FindRoot with a better initial estimate

data = {#, vi /. FindRoot[v[#] == 0, {vi, .1}]} & /@
Range[39/10, 592/10, inc];

ListLinePlot[data,
PlotRange -> All,
Frame -> True,
Axes -> False,
FrameLabel -> (Style[#, 16] & /@ {"atm", "vi"})]

Bob Hanlon

On Wed, Oct 9, 2013 at 2:11 AM, Cory <leahyc1 at apps.tcnj.edu> wrote:

> Hello
>
> I need to use the Newton Raphson Method to find values of Specific Volume
> from the Van der Waal equation over a process of constant Temperature but
> variant Pressure.
>
> I've worked Mathematica to be able to spit out a list of however many
> iterations I want between the desired Pressure min and max (3.9 atm to 59.2
> atm).  Further, I am able to find the root of a single specified element in
> the list.  However, I am unable to figure out how to get the roots
> (Specific volumes) for all elements at once.
>
> For example:
>
> ----------------------------------------------------------
>
>  FindRoot[v[] == 0, {vi, 4}, WorkingPrecision -> 20]
>
> ----------------------------------------------------------
>
> will show vi, specific volume, for the 59th element in the list.
>
> I've tried the following, thinking this would work for multiple elements:
>
> ----------------------------------------------------------
>
> FindRoot[v[[1;;60]] == 0, {vi, 4}, WorkingPrecision -> 20]
>
> ----------------------------------------------------------
>
> However I receive an error.
>
> "FindRoot::nveq: "The number of equations does not match the number of
> variables in FindRoot[v[[1;;60]]==0,{vi,4},WorkingPrecision->20].""
>
> This is my code:
>
> ----------------------------------------------------------
>
> a = 1.36;
> b = .003183;
> R = .0820578;
> T = 333;
> inc = (59.2 - 3.9)/60;
>
> v = Table[
>   vi - ((((atm) + (a/vi^2)) (vi - b) - (R*T))/((atm) - (a/
>          vi^2) + (2 a*b/vi^3))), {atm, 3.9, 59.2, inc}]
>
> FindRoot[v[] == 0, {vi, 4}, WorkingPrecision -> 20]
>
> ---------------------------------------------------------
>
> Any help would be greatly appreciated!  Thanks
>
>

```

• Prev by Date: Re: Newton-Raphson Root Finding, Difficulty in coding
• Next by Date: Program to generate more members of the sequence A065978 in http://www.oeis.org/
• Previous by thread: Re: Newton-Raphson Root Finding, Difficulty in coding
• Next by thread: Re: Weighting in simultaneous NonlinearModelFits