Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
You might have to expand manually, using the definition for the Fourier coefficients (and thus NIntegrate[]). –  J. M. Aug 1 '12 at 14:27
2  
Something like 2 NIntegrate[f[t] Sin[n t], {t, 0, Pi}]/Pi to generate your series coefficients, I meant. –  J. M. Aug 1 '12 at 14:31
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 1 '12 at 14:47
1  
Instead of (u^(0,1))[t,xMin], maybe it's Derivative[0,1][u][t,xMin] what you want? –  Silvia Aug 2 '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 2 '12 at 20:40
show 8 more comments

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  drN Aug 3 '12 at 2: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 3 '12 at 8: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! –  drN Aug 7 '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 7 '12 at 12:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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