Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #16805
| From | steviep <ssplotkin@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Using FindRoot with free parameters |
| Date | 2014-04-15 03:01 +0000 |
| Message-ID | <lii7dh$iio$1@smc.vnet.net> (permalink) |
| Organization | Time-Warner Telecom |
>
> f[n_, x_] = Exp[-3 x^2 + 2] BesselI[n, 4 x];
>
>
> xf[alpha_?NumericQ, n_?NumericQ] :=
> Module[{x}, x /.
> FindRoot[f[n, x] - alpha, {x, 2}][[1]]]
>
>
> xf[3, 0]
>
>
> 1.11426
>
>
> xf[alpha, n] /. {alpha -> 3, n -> 0}
>
>
> 1.11426
>
>
>
> Bob Hanlon
>
>
>
>
> On Sat, Apr 12, 2014 at 5:15 AM, steviep2
> <ssplotkin@gmail.com> wrote:
>
> > Hi,
> > I want to define a function of 2 parameters that uses FindRoot. I.e. I
> > have a known but complicated function f[n_,x_] = "complicated function of
> > (n,x)". I want to find the value of x where f[n,x] == alpha, and I want to
> > call this a function xf[alpha_,n_].
> >
> > So my attempts (this is non-working code) looks something like this:
> >
> > xf[alpha_, n_] = Function[{x}, x /. FindRoot[f[n,x] - alpha, {x, 2}]]
> >
> > or
> > xf[alpha_, n_] = Function[x /. FindRoot[f[n, x] - alpha, {x, 2}]][alpha,
> > n]
> >
> > It seems this is a pretty simple question-- basically using FindRoot but
> > holding off on substituting in the parameters until later. Is there a
> > simple solution?
Thanks,
I had actually come up this solution in the meantime:
xf[alpha_, n_] = Function[{alpha, n}, x /. FindRoot[f[n, x] - alpha, {x, 2}]][alpha,n]
which gives the same answer. It also gives a bunch of warnings, as does Module when "=" is used instead of ":=".
Is one method preferred over another? Thanks in any event.
-S
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar
Re: Using FindRoot with free parameters steviep <ssplotkin@gmail.com> - 2014-04-15 03:01 +0000
csiph-web