Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7204 > unrolled thread

Function calling another function that uses NSolve - can't get this

Started byjdm <james.d.mclaughlin@gmail.com>
First post2011-12-14 11:09 +0000
Last post2011-12-30 12:14 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Function calling another function that uses NSolve - can't get this jdm <james.d.mclaughlin@gmail.com> - 2011-12-14 11:09 +0000
    Re: Function calling another function that uses NSolve - can't get this Ray Koopman <koopman@sfu.ca> - 2011-12-15 10:00 +0000
      Re: Function calling another function that uses NSolve - can't get this jdm <james.d.mclaughlin@gmail.com> - 2011-12-30 12:14 +0000

#7204 — Function calling another function that uses NSolve - can't get this

Fromjdm <james.d.mclaughlin@gmail.com>
Date2011-12-14 11:09 +0000
SubjectFunction calling another function that uses NSolve - can't get this
Message-ID<jca04g$a2h$1@smc.vnet.net>
I was trying to convert a function (advantagesecondalttheoretic below)
from another system to Mathematica. Probably because the function it in turn
called used NSolve, I couldn't seem to get it to work while it called
this function - it seemed that where secondaltb output {b->whatever
value}, there was no way for advantagesecondalttheoretic to access
this value. I ended up having to call the secondaltb function
separately, and then manually input the result from it to a new
version of advantagesecondalttheoretic - the one below:

This is, naturally, not much help if I want to plot any graphs!

Could someone please take a look at the below code and tell me how I
can get advantagesecondalttheoretic to call secondaltb and use the
value of b that results from it? Thanks!

secondaltb[KP_, Ps_, C_, M_] :=
 NSolve[Sqrt[2*M]*b +
    InverseCDF[NormalDistribution[0, 1], Ps]*
     Sqrt[4*(InverseCDF[NormalDistribution[0, 1], Ps]^2) +
       4*Sqrt[2*M]*b + 2.027226163*M] ==
   KP*C - 2*(InverseCDF[NormalDistribution[0, 1], Ps]^2), b,
  WorkingPrecision -> 20]

lnscale = N[1/(2*Log[2]), 20]

sb = secondaltb[2^64, 0.95, 2^(-55.38), 2295]

{{b -> 3.8915440624385913563}}

advantagesecondalttheoretic[b_] := (lnscale*(b^2)) + Log2[b] +
  Log2[Sqrt[2*Pi]]

N[advantagesecondalttheoretic[3.8915440624385913563], 20]

14.210260698586953991

[toc] | [next] | [standalone]


#7231

FromRay Koopman <koopman@sfu.ca>
Date2011-12-15 10:00 +0000
Message-ID<jccggn$mi3$1@smc.vnet.net>
In reply to#7204
On Dec 14, 3:09 am, jdm <james.d.mclaugh...@gmail.com> wrote:
> I was trying to convert a function (advantagesecondalttheoretic below)
> from another system to Mathematica. Probably because the function it in turn
> called used NSolve, I couldn't seem to get it to work while it called
> this function - it seemed that where secondaltb output {b->whatever
> value}, there was no way for advantagesecondalttheoretic to access
> this value. I ended up having to call the secondaltb function
> separately, and then manually input the result from it to a new
> version of advantagesecondalttheoretic - the one below:
>
> This is, naturally, not much help if I want to plot any graphs!
>
> Could someone please take a look at the below code and tell me how I
> can get advantagesecondalttheoretic to call secondaltb and use the
> value of b that results from it? Thanks!
>
> secondaltb[KP_, Ps_, C_, M_] :=
>  NSolve[Sqrt[2*M]*b +
>     InverseCDF[NormalDistribution[0, 1], Ps]*
>      Sqrt[4*(InverseCDF[NormalDistribution[0, 1], Ps]^2) +
>        4*Sqrt[2*M]*b + 2.027226163*M] ==
>    KP*C - 2*(InverseCDF[NormalDistribution[0, 1], Ps]^2), b,
>   WorkingPrecision -> 20]
>
> lnscale = N[1/(2*Log[2]), 20]
>
> sb = secondaltb[2^64, 0.95, 2^(-55.38), 2295]
>
> {{b -> 3.8915440624385913563}}
>
> advantagesecondalttheoretic[b_] := (lnscale*(b^2)) + Log2[b] +
>   Log2[Sqrt[2*Pi]]
>
> N[advantagesecondalttheoretic[3.8915440624385913563], 20]
>
> 14.210260698586953991

It helps if you make all the arguments exact.

secondaltb[KP_, Ps_, C_, M_, wp_:20] :=
With[{z = N[-Sqrt[2]*InverseErfc[2*Ps], wp]},
NSolve[Sqrt[2*M]*b + z*Sqrt[4*z^2 + 4*Sqrt[2*M]*b + M*2027226163*^-9]
        == KP*C - 2*z^2, b, WorkingPrecision -> wp] ]

sb = b /. secondaltb[2^64, 95/100, 2^(-5538/100), 2295][[1]]
     b /. secondaltb[2^64, 95/100, 2^(-5538/100), 2295, 30][[1]]

3.8915440624386002540
3.89154406243860025402669707577

[toc] | [prev] | [next] | [standalone]


#7481

Fromjdm <james.d.mclaughlin@gmail.com>
Date2011-12-30 12:14 +0000
Message-ID<jdk9up$8di$1@smc.vnet.net>
In reply to#7231
A belated thanks to Ray and Bob - Bob in particular provided the
advice which overcame the problem two weeks ago, but both of your
postings provided some very helpful advice which will be extremely
useful in future!

James.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web