MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to "dynamically" define such a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25688] Re: how to "dynamically" define such a function
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Thu, 19 Oct 2000 04:35:17 -0400 (EDT)
  • References: <8sjhkv$fol@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

One way:

F[x_] := f[NestWhile[# - 1 &, m, x <= L[#] &]][x]

If L takes significact time to compute, we might cash it:

F[x_] := f[NestWhile[# - 1 &, m, x <= (L[#] = L[#]) &]][x]

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Zhu X. P." <xpzhu at red.semi.ac.cn> wrote in message
news:8sjhkv$fol at smc.vnet.net...
> hello all,
>
> I want to define a function like this:
>
> F[x]=
>         f[x]=f[m][x]                      x>L[m],
>         f[x]=f[m-1][x]                    L[m-1]<x<L[m],
>         ....                              ...
>         f[x]=f[1][x]                      L[1]<x<L[2],
>         f[x]=f[0][x]                      x<L[1]
>
> "Dynamically define" means "m" is not a fixed number. When m, as well as
> L[i] and f[i][x] (i =,1,...,m), is given,  F[x] is defined.
> I define F[x] as below:
> F[x_] =
>   Module[{n, w},
>               w[x_, 0] = f[0][x];
>               w[x_, n_] = If[x > L[n], f[n][x], w[x, n - 1]];
>               w[x, m]
>             ];
> I think this method is not very good. Are there some better ways to
> define such a function?
> ps. I want to integrate this function F[x]:
> Integrate[F[x], {x,a,b}]
> when a>L[m], no problem. But when a<L[m] Mathematica tell me like this:
>
> In[48]:=Integrate[F[x], {x, .2, 10}]
> Out[48]:=\!\(\[Integral]\_0.2`\%21 If[x > 0.9000000000000001`,
> \(f[7]\)[x - L[7 - 1]],
>         w$52[x, 7 - 1]] \[DifferentialD]x\)
>
> where m=7, 0.9 is the value of L[7]. Who can tell me why this happened?
>
> thank you!
>
> Zhu X. P.
>




  • Prev by Date: Re: Change objetive function in Non-Linear Fit
  • Next by Date: Re: A question of matrix multiply, who can solve it?
  • Previous by thread: how to "dynamically" define such a function
  • Next by thread: Compiled functions in NDSolve.