Re: variable amount of Interpolation points
- To: mathgroup at smc.vnet.net
- Subject: [mg123756] Re: variable amount of Interpolation points
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sat, 17 Dec 2011 02:48:15 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
On 12/16/11 at 5:53 AM, konstantinweixelbaum at googlemail.com (Konny)
wrote:
>Is there a way to iterate inside an interpolation??
>I am thinking to make the amount of interpolation points variable.
>I tried this, but had no luck
>Interpolation[{For[i = 0, i < 4, i++, {i, 2 i}]}]
This doesn't work because For returns a Null and there is
nothing to interpolate. You can achieve your intent with:
Interpolation[Table[{k, 2 k}, {k, 0, 3}]]
Bottom line: don't use For. And if you want another reason to
not use For consider:
In[3]:= AbsoluteTiming[
For[sum = k = 0, k <= 1000000, k++, sum += k]; sum]
Out[3]= {1.713264,500000500000}
In[4]:= AbsoluteTiming[Total@Range[1000000]]
Out[4]= {0.224719,500000500000}
In[5]:= AbsoluteTiming[Sum[n, {n, m}] /. m -> 1000000]
Out[5]= {0.077688,500000500000}