1
$\begingroup$

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?

$\endgroup$
13
  • $\begingroup$ You might have to expand manually, using the definition for the Fourier coefficients (and thus NIntegrate[]). $\endgroup$ Commented Aug 1, 2012 at 14:27
  • 2
    $\begingroup$ Something like 2 NIntegrate[f[t] Sin[n t], {t, 0, Pi}]/Pi to generate your series coefficients, I meant. $\endgroup$ Commented Aug 1, 2012 at 14:31
  • 1
    $\begingroup$ 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. $\endgroup$
    – acl
    Commented Aug 1, 2012 at 14:47
  • 1
    $\begingroup$ Instead of (u^(0,1))[t,xMin], maybe it's Derivative[0,1][u][t,xMin] what you want? $\endgroup$
    – Silvia
    Commented Aug 2, 2012 at 20:14
  • 2
    $\begingroup$ 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. $\endgroup$
    – acl
    Commented Aug 2, 2012 at 20:40

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – dearN
    Commented Aug 3, 2012 at 2:11
  • $\begingroup$ 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. $\endgroup$
    – acl
    Commented Aug 3, 2012 at 8:44
  • $\begingroup$ 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! $\endgroup$
    – dearN
    Commented Aug 7, 2012 at 12:44
  • $\begingroup$ I am not sure what deeper could be going on (or what you are trying to say), but OK :) $\endgroup$
    – acl
    Commented Aug 7, 2012 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.