Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interpolation and plot doing strange things with mathematica 6 tia

114 views
Skip to first unread message

ratull...@gmail.com

unread,
May 22, 2008, 2:41:50 AM5/22/08
to
Greetings All

I run these commands that I've had plenty of help getting to
work...but the plot doesn't follow the points, as you can see in the
plot. At the end it just goes crazy and when I test the points with

input s[0]
output is -3.73293
why are the numbers so out of sync... at s[0] it should be -2 not
-3.73293

I try increasing the number in the line
N[FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]]
(I've changed the number 25 to over 100 and the problem seems to get
worse)

See code below:

In[89]:= data3 = {{0, -2}, {7, 1}, {10, 6}, {12, -2}, {18, -6}, {27,
6}, {34,
4}, {42, -6}, {49, -5}, {56, 4}, {62, 3}, {67, -5}, {70, -3}, {79,
3}, {83, 7}, {88, -3}, {89, -8}, {96, 7}, {105,
9}, {113, -8}, {122, -9}, {131, 9}, {132,
1}, {134, -9}, {138, -2}};
f = Interpolation[data3, PeriodicInterpolation -> True];

<< "FourierSeries`"

s[x_] = N[
FourierTrigSeries[f[x], x, 25, FourierParameters -> {-1, 1/138}]]

discr = Interpolation[data3 /. {x_, y_} -> {x, y},
InterpolationOrder -> 1];

g[x_] = Piecewise[{{discr[x], 0 < x < 138}, {0, True}}];

Show[Plot[s[x], {x, 0, 138}, PlotStyle -> Red,
PlotRange -> {-15, 15}], Plot[g[x], {x, 0, 138}, Filling -> Axis],
ListPlot[data3, Filling -> Axis, PlotRange -> {0, 138}]]

tia sal2

Jens-Peer Kuska

unread,
May 22, 2008, 6:18:06 AM5/22/08
to
Hi,

if you make a approximation based on a Fourier series
it converges "in the middle" and never point wise
The most famous example is the Gibbs phenomenon.
http://en.wikipedia.org/wiki/Gibbs_phenomenon

Regards
Jens

ratull...@gmail.com

unread,
May 23, 2008, 3:12:50 AM5/23/08
to
On May 22, 12:18 am, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:

> Hi,
>
> if you make a approximation based on a Fourier series
> it converges "in the middle" and never point wise
> The most famous example is the Gibbs phenomenon.http://en.wikipedia.org/wiki/Gibbs_phenomenon
>
> Regards
> Jens
>

can anyone recommend a work around while still keeping the output in
the format as sin and cos or is this not possible?
tia sal2

Jens-Peer Kuska

unread,
May 24, 2008, 3:53:15 AM5/24/08
to
Hi,

from the point of signal processing not. But you can try to
use a spline interpolation that has not the tendency to
oscillate and resample the data or use the resampled
data for your trigonometric approximation.
I would recommend an Akima spline.
If you don't have a non parametric spline computation
take my http://phong.informatik.uni-leipzig.de/~kuska/NonParametricSplines.zip
package, install it in your Mathematica/Applications/AddOns directory
and have a look into the documentation (DocumentationCenter/Installed
AddOns).

Regards
Jens

Daniel Lichtblau

unread,
May 24, 2008, 3:55:45 AM5/24/08
to
ratull...@gmail.com wrote:
> On May 22, 12:18 am, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
> wrote:
>
>>Hi,
>>
>>if you make a approximation based on a Fourier series
>>it converges "in the middle" and never point wise
>>The most famous example is the Gibbs phenomenon.http://en.wikipedia.org/wiki/Gibbs_phenomenon
>>
>>Regards
>> Jens
>>
> can anyone recommend a work around while still keeping the output in
> the format as sin and cos or is this not possible?
> tia sal2

This may be a bit better behaved, numerically. Use a different
integration dummy variable for your Fourier series

<< "FourierSeries`"
s1[x_] = FourierTrigSeries[f[x], y, 25,
FourierParameters -> {-1, 1/138}];

s[x_Real] := Block[{y}, (s1[y] /. Integrate -> NIntegrate) /. y -> x]

Now s[0.] and s[138.] give 2.0, as desired.

In[124]:= s[0.]
Out[124]= -2.

In[125]:= s[138.]
Out[125]= -2.

Daniel Lichtblau
Wolfram Research

Mirek

unread,
Jun 27, 2008, 6:23:45 AM6/27/08
to
On 24 Maj, 09:53, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:
> Hi,
>

> from the point of signal processing not. But you can try to
> use a spline interpolation that has not the tendency to

^^^^^^^^^^^^^^^
> oscillate
^^^^^^^^
It has either but differently - short oscillation, higher overshot:

fig 1.1
http://www.cisl.ucar.edu/css/staff/flyer/ffgibbs.pdf

0 new messages