Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4450 > unrolled thread
| Started by | WetBlanket <wyvern864@gmail.com> |
|---|---|
| First post | 2011-08-18 07:24 +0000 |
| Last post | 2011-08-19 10:41 +0000 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Inverse Interpolation WetBlanket <wyvern864@gmail.com> - 2011-08-18 07:24 +0000
Re: Inverse Interpolation "Alexey Popkov" <lehin.p@gmail.com> - 2011-08-19 10:40 +0000
Re: Inverse Interpolation "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-19 10:41 +0000
| From | WetBlanket <wyvern864@gmail.com> |
|---|---|
| Date | 2011-08-18 07:24 +0000 |
| Subject | Inverse Interpolation |
| Message-ID | <j2iens$bkv$1@smc.vnet.net> |
Previously, the following code could be used to use the Plot functions
algorithm to select point at which to evaluate a function to assist in
obtaining a good numerical interpolation. In Version 8 this code does
not seem to work ( at least for me). Can someone assist me by showing
how this task is best accomplished in Version 8. I use the Cos
function in this example for simplicity. Clearly, numerical
interpolation is not needed to obtain an inverse for the Cos.
list={};
F = Cos[x];
Plot[ ( ss=F; AppendTo[list, {ss,x}]; ss), {x,-1,1}, PlotPoints-
>1000,
PlotRange->All, AxesLabel->{"x","F"}]
Thanks for the help.
[toc] | [next] | [standalone]
| From | "Alexey Popkov" <lehin.p@gmail.com> |
|---|---|
| Date | 2011-08-19 10:40 +0000 |
| Message-ID | <j2leik$nh9$1@smc.vnet.net> |
| In reply to | #4450 |
"WetBlanket" <wyvern864@gmail.com> wrote: news:j2iens$bkv$1@smc.vnet.net...
> Previously, the following code could be used to use the Plot functions
> algorithm to select point at which to evaluate a function to assist in
> obtaining a good numerical interpolation. In Version 8 this code does
> not seem to work ( at least for me). Can someone assist me by showing
> how this task is best accomplished in Version 8. I use the Cos
> function in this example for simplicity. Clearly, numerical
> interpolation is not needed to obtain an inverse for the Cos.
>
> list={};
> F = Cos[x];
>
> Plot[ ( ss=F; AppendTo[list, {ss,x}]; ss), {x,-1,1}, PlotPoints-
>>1000,
> PlotRange->All, AxesLabel->{"x","F"}]
>
> Thanks for the help.
Evaluation of your code in Mathematica 7.0.1 gives error:
AppendTo::rvalue: {} is not a variable with a value, so its value cannot be
changed. >>
Tracing of the evaluation shows that AppendTo is called with '{}' as the
first argument instead of the 'list' variable:
AppendTo[{},{0.540304,-0.999998}]
It means that 'list' is somehow evaluated inside of AppendTo in spite of the
HoldFirst attribute of AppendTo:
In[7]:= Attributes@AppendTo
Out[7]= {HoldFirst, Protected}
Looks like a bug or at least a big inconsistency.
One workaround is to use undocumented option Evaluated->False:
Plot[(ss = F; AppendTo[list, {ss, x}]; ss), {x, -1, 1}, PlotPoints -> 1000,
PlotRange -> All, AxesLabel -> {"x", "F"}, Evaluated -> False]
With this option your code works as expected. Another way is to define your
function with restriction to numeric values only and move AppendTo inside of
the function code:
list = {};
f[x_?NumericQ] := (AppendTo[list, {ss = Cos[x], x}]; ss); Plot[
f[x], {x, -1, 1}, PlotPoints -> 100, PlotRange -> All,
AxesLabel -> {"x", "F"}]
Note that there is convenient and much more computationally and
memory-efficient way to collect evaluation points using Reap and Sow:
results =
Reap[Plot[(Sow[{x, ss = F}]; ss), {x, -1, 1}, PlotPoints -> 1000,
PlotRange -> All, AxesLabel -> {"x", "F"}]];
plot = results[[1]]
list = results[[2]]
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-08-19 10:41 +0000 |
| Message-ID | <j2lelg$ni5$1@smc.vnet.net> |
| In reply to | #4450 |
On Thu, 18 Aug 2011 08:24:44 +0100, WetBlanket <wyvern864@gmail.com> wrote:
> Previously, the following code could be used to use the Plot functions
> algorithm to select point at which to evaluate a function to assist in
> obtaining a good numerical interpolation. In Version 8 this code does
> not seem to work ( at least for me). Can someone assist me by showing
> how this task is best accomplished in Version 8. I use the Cos
> function in this example for simplicity. Clearly, numerical
> interpolation is not needed to obtain an inverse for the Cos.
>
> list={};
> F = Cos[x];
>
> Plot[ ( ss=F; AppendTo[list, {ss,x}]; ss), {x,-1,1}, PlotPoints-
>> 1000,
> PlotRange->All, AxesLabel->{"x","F"}]
>
> Thanks for the help.
>
list = {};
F = Cos[x];
Plot[
F, {x, -1, 1},
PlotPoints -> 1000, PlotRange -> All, AxesLabel -> {"x", "F"},
EvaluationMonitor :> AppendTo[list, {F, x}]
]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web