1

I am having a tough time formulating the right question but here goes.

I know that solving the pde as in here gives me an interpolating function. I understand that the interpolating function object is different from the interpolating polynomial.

So if I wanted to approximate the interpolating function through FourierSinSeries, I don't quite get how I might go about it.

I can't just do:

FourierSinSeries[InterpolatingFunction[{{0.,...},{0.,...},{0.,TMax}},<>],x,4]

I tried that it didn't quite give me a series expansion.

Edit:

Here's what I tried to do to get fourier coefficients describing my interpolating function.

Mathematica code:

Off[NDSolve::ibcinc];
k=0.0677;
{xMin,xMax}={-(\[Pi]/k),\[Pi]/k};
TMax=2500;
uSol[t_,x_]=u[t,x]/.NDSolve[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\(u[t, x]\)\)==-100 \!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]\((
\*SuperscriptBox[\(u[t, x]\), \(3\)]\ 
\*SubscriptBox[\(\[PartialD]\), \(x, x, x\)]u[t, x])\)\)+1/3 \!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]\((
\*SuperscriptBox[\(u[t, x]\), \(3\)]\ 
\*SubscriptBox[\(\[PartialD]\), \(x\)]u[t, x])\)\)-5 \!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]\((
\*SuperscriptBox[\((
\*FractionBox[\(u[t, x]\), \(1 + u[t, x]\)])\), \(2\)]\ 
\*SubscriptBox[\(\[PartialD]\), \(x\)]u[t, x])\)\),u[0,x]==1-0.1 Cos[k x],
(*Piecewise Function for INITIAL CONDITION*)
(*u[0,x]== Piecewise[{{-0.1,-\[Pi]/k<= x<-\[Pi]/(10 k)},{ Cos[x],-\[Pi]/(10 k)<= x<= \[Pi]/(10 k)},{-0.1,\[Pi]/(10 k)<x<= \[Pi]/k}}],*)

(u^(0,1))[t,xMin]==0,
(u^(0,1))[t,xMax]==0,
(u^(0,3))[t,xMin]==0,
(u^(0,3))[t,xMax]==0

(*(u^(0,3))[t,xMin]==0,
(u^(0,3))[t,xMax]==0*)},
u,{t,0,TMax},{x,xMin,xMax},MaxStepSize->0.1,MaxSteps->100000,Method->{"BDF", "MaxDifferenceOrder"-> 5}][[1]]

Fourier series:

Since I now have uSol which, my fourier coeffs should be:

I1 = NIntegrate[uSol[0.1 TMax, x], {x, xMin, xMax}] (*I1 at time=0.1 TMax*)
a0 = (1/(2*xMin))*I1
an = NIntegrate[uSol[0.1 TMax, x] Cos[n \[Pi] x/xMax], {x, xMin, xMax}]
bn = NIntegrate[uSol[0.1 TMax, x] Sin[n \[Pi] x/xMax], {x, xMin, xMax}]

Using NIntegrate errors out with:

NIntegrate::inumr: The integrand Cos[0.0677 n x] <<1>>[250.,x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{-46.4046,-46.3046}}. >>

However, using Integrate instead of NIntegrate gave me just the input as symbols.

Neither is the coefficient.

So what am I missing? There has to be a simpler way of figurijng out the fourier coeffs of an interpolating function. can I export data out of mathematica into .csv or some other format which is not dependent on mathematica to be interpreted?

dearN
  • 5,341
  • 3
  • 35
  • 74
  • You might have to expand manually, using the definition for the Fourier coefficients (and thus NIntegrate[]). – J. M.'s missing motivation Aug 01 '12 at 14:27
  • @J.M. I am sorry but I don't entirely understand what that means. How do I go about expanding the interpolating function object manually? And why NIntegrate[]? – dearN Aug 01 '12 at 14:28
  • 2
    Something like 2 NIntegrate[f[t] Sin[n t], {t, 0, Pi}]/Pi to generate your series coefficients, I meant. – J. M.'s missing motivation Aug 01 '12 at 14:31
  • @J.M. Ohhh! I see what you mean. Now it makes sense when you say, "use the definition of the fourier coefficients".... don't know why I didn't think of that! – dearN Aug 01 '12 at 14:33
  • 1
    you could also fourier sine transform the functions you're solving, end up with equations for the coefficients and solve those. but that is more work than what JM says. – acl Aug 01 '12 at 14:47
  • @acl Goes to show how poor my math skills are! :P – dearN Aug 01 '12 at 16:25
  • @J.M. Added more details. Have failed miserably at getting the fourier coeffs. – dearN Aug 02 '12 at 18:55
  • 1
    Instead of (u^(0,1))[t,xMin], maybe it's Derivative[0,1][u][t,xMin] what you want? – Silvia Aug 02 '12 at 20:14
  • 2
    NIntegrate can't integrate symbolic arguments. You haven't fixed n so the integrand is not numerical; fix n to something and it should work. Unfortunately cut and pasting doesn't work for the reason @Silvia gave; if you fix that maybe we can help more easily. – acl Aug 02 '12 at 20:40
  • also, isn't the question "suppose I have an interpolating function eg fn = Interpolation[Table[{x, x^2}, {x, 0, 2 \[Pi], .1}]]; and I try to calculate the nth coefficient of the fourier cos series as fn = Interpolation[Table[{x, x^2}, {x, 0, 2 \[Pi], .1}]];; it gives such and such an error; what am I doing wrong?" there's no need for the NDSolve etc – acl Aug 02 '12 at 21:20
  • @Silvia Aren't they both the same? – dearN Aug 03 '12 at 02:13
  • @DNA no, they are not the same at all. the Derivative[0,1][u][t,xMin] display like (u^(0,1))[t,xMin] just for 2-D display in a notebook frontend, it has different underlying structure for interpretation. Refer to the InverseFunction example in this doc, please. Converting code to InputForm (Select the code, press ctrl+shift+i) before post it might be more convenient. – Silvia Aug 03 '12 at 08:52
  • @Silvia Thank you! – dearN Aug 07 '12 at 12:43

1 Answers1

3

Preliminary

First let me change the PDE that is being solve to make things go a bit faster:

k = 0.0677;
{xMin, xMax} = {-(\[Pi]/k), \[Pi]/k};
TMax = 100;
uSol[t_, x_] = u[t, x] /. NDSolve[{\!\(
\*SubscriptBox[\(\[PartialD]\), \(t\)]\(u[t, x]\)\) == (u[t, x] \!\(
\*SubscriptBox[\(\[PartialD]\), \(x, x\)]\(u[t, x]\)\)), 
     u[0, x] == 1 - 0.1 Cos[k x],
     Derivative[0, 1][u][t, xMin] == 0,
     Derivative[0, 1][u][t, xMax] == 0},
    u, {t, 0, TMax}, {x, xMin, xMax}, MaxStepSize -> 0.1][[1]]

Answer

You want to calculate the nth coefficient, and try

an = NIntegrate[uSol[0.1 TMax, x] Cos[n \[Pi] x/xMax], {x, xMin, xMax}]
bn = NIntegrate[uSol[0.1 TMax, x] Sin[n \[Pi] x/xMax], {x, xMin, xMax}]

which fails with

NIntegrate::inumr: The integrand Cos[0.0677 n x] <<1>> [10.,x] has evaluated to
 non-numerical values for all sampling points in the region with boundaries
  {{-46.4046,-46.3046}}.

This is literal and obviously true: n isn't fixed here. If I fix n it does give a result:

ClearAll[an, bn]
With[
 {n = 1},
 an = NIntegrate[
   uSol[0.1 TMax, x] Cos[n \[Pi] x/xMax], {x, xMin, xMax}];
 bn = NIntegrate[
   uSol[0.1 TMax, x] Sin[n \[Pi] x/xMax], {x, xMin, xMax}];
 ]
an
bn

(*
-4.43265
5.73641*10^-12
*)

(it also emits some warnings probably related to the fact that the $b_n$ actually is zero--although I could be wrong).

Anyway, I don't know if this is the best way to go about it, but this seems to work.

acl
  • 19,834
  • 3
  • 66
  • 91
  • Yes, this probably works but I don't know yet know the physical significance of holding n constant. I'll have to think deep and hard about this. – dearN Aug 03 '12 at 02:11
  • What do you mean? You need n numerical to do the integral numerically, but you could do it for n=1, 2 etc. there's nothing deeper going on. – acl Aug 03 '12 at 08:44
  • There might be something deeper going on as far as what n represents as far as harmonics being used as an input to simulate a very thin evaporating liquid film. But thank you! – dearN Aug 07 '12 at 12:44
  • I am not sure what deeper could be going on (or what you are trying to say), but OK :) – acl Aug 07 '12 at 12:46