Using FEM and NDSolve

I have to solve the ODE $$u''[t]+u'[t]+\sin {(5t)} u[t]=t^3-t$$, with $$u[0]=0,u[1]=0,$$ with a finite element method and then with NDSolve.

Finally, I have to calculate $$|u_{FEM}-u_{NDSolve}|$$ and if the inequality

$$\sqrt {\int_{a}^{b}[u(t)]^2dt} \le \frac{b-a}{\sqrt 2} \sqrt {\int_{a}^{b}[u_t(t)]^2dt}$$ holds for $$b=1,a=0.$$

I used:

ic1 = {u[0] == 0, u[1] == 0};
ode = u''[t] + u'[t] + Sin[5 t] u[t] == t^3 - t;
sol = NDSolve[{ode, ic1}, u, {t, 0, 20},
Method -> {"FiniteElement",
MeshOptions -> MaxCellMeasure -> 0.001}][[1]];
bctraditional = {u[0] == 0, u[1] == 0};

Plot[Evaluate[u[t] /. {sol, soltraditional}], {t, 0, 20},
AxesOrigin -> {0, 0}, PlotRange -> All,
PlotStyle -> {Automatic, {Red, Dashed}}]


On the other hand, I used:

sol = NDSolve[{u''[t] + u'[t] + Sin[5 t] u[t] == t^3 - t, u[0] == 0,
u[1] == 0}, u[t], t]
Plot[u[t] /. sol, {t, 0, 1}]


but I couldn't find an expression for $$u[t]$$ and not the same results and not able to apply the integrals. Any help? Thank you

• What's $u_{FED}$? That is, is FED supposed to be FEM? – Michael E2 Mar 24 '20 at 15:35
• Yes, u are right, I corrected it – George Mar 24 '20 at 15:42
• Any help for the last two questions? – George Mar 24 '20 at 19:38

What about using NDSolveValue? It can directly return the interpolating function:

ode = u''[t] + u'[t] + Sin[5 t] u[t] == t^3 - t;
uFEM = NDSolveValue[{ode, DirichletCondition[u[t] == 0, True]},
u,
{t, 0, 1},
Method -> {"FiniteElement","MeshOptions" -> MaxCellMeasure -> 0.001}
];
utraditional = NDSolveValue[{ode, u[0] == 0, u[1] == 0}, u, {t, 0, 1}];


Notice the use of DirichletCondition to get FEM working. As far as I understood the user interface, "FiniteElement" can only handle Dirichlet conditions if they really lie on the boundary. Thus {t, 0, 20} won't work correctly.

Now you can use uFEM and utraditional like any other function u, i.e., you do not have to mess around with ReplaceAll (/.). For example:

Plot[uFEM[t] - utraditional[t], {t, 0, 1}, PlotRange -> All]


Sqrt[NIntegrate[uFEM[t]^2, {t, 0, 1}]] <=
Sqrt[NIntegrate[uFEM'[t]^2, {t, 0, 1}]]/Sqrt[2]

• @George the FEM Options tutorial has a section on what triggers the use FEM in NDSolve. Perhaps useful. – user21 Mar 25 '20 at 8:21