4
$\begingroup$

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};
soltraditional = NDSolve[{ode, bctraditional}, u, {t, 0, 20}][[1]];

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

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

1 Answer 1

5
$\begingroup$

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]

enter image description here

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

True

True

$\endgroup$
2
  • 1
    $\begingroup$ Thanks. Can you help me with the last two questions? $\endgroup$
    – George
    Commented Mar 24, 2020 at 15:08
  • 2
    $\begingroup$ @George the FEM Options tutorial has a section on what triggers the use FEM in NDSolve. Perhaps useful. $\endgroup$
    – user21
    Commented Mar 25, 2020 at 8:21

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.