This is on 11.3, windows 7
I have not used Mathematica FEM much at all. So sorry for this basic question on using it to solve a basic second order initial value ODE.
I want to use NDSolve
but force it to use FEM to solve a time dependent initial value ODE. (spring/damped system).
My understanding is that, to use FEM, one just needs to change the initial conditions from y[0]==0,y'[0]==0
to use DirichletCondition[y[t] == 0, t == 0]
and NeumannValue[0, t == 0]
, and then use NDSolve
as before, but also add the Method -> {"FiniteElement"}
as an option.
Is this how one tells NDSolve
to use FEM? I am doing something wrong in what follows, since I get wrong answer from NDSolve
when I did the above. So I think my initial conditions are not specified correctly.
Problem
Solve y''[t] + y'[t] + 3 y[t] == Sin[t]
with y[0]==0,y'[0]==0
NDSolve
ClearAll[y,t];
ode = y''[t]+y'[t]+3y[t]==Sin[t];
ic = {y[0]==0,y'[0]==0};
sol = NDSolve[{ode,ic},y,{t,0,20}];
Plot[Evaluate[y[t]/.sol],{t,0,20},AxesOrigin->{0,0},PlotRange->All]
I want to get same solution as above, but want to force NDSolve
to use FEM.
NDSolve with FEM
ClearAll[y,t];
ic1 = DirichletCondition[y[t]==0,t==0];
ic2 = NeumannValue[0,t==0];(*this is not even needed*)
ode = y''[t]+y'[t]+3y[t]==Sin[t]+ic2;
sol = NDSolve[{ode,ic1},y,{t,0,20},Method->{"FiniteElement"}];
Plot[Evaluate[y[t]/.sol],{t,0,20},AxesOrigin->{0,0},PlotRange->All]
Which is not correct. I noticed that I can't just write
ClearAll[y,t];
ic = {y[0]==0,y'[0]==0};
ode = y''[t]+y'[t]+3y[t]==Sin[t];
sol = NDSolve[{ode,ic},y,{t,0,20},Method->{"FiniteElement"}]
As this gives an error. So that is why I changed initial conditions to use DirichletCondition
I think my error is in the "boundary" conditions settings. But I do not know where and how to fix it. The problem is that removing NeumannValue[0,t==0]
still gives the same solution. My understanding is that NeumannValue==0
is the default always, that is why removing it makes no change to the solution.
I also understand that FEM is typically used for static problems (or steady state, no time dependence). So the DirichletCondition
and NeumannValue
typically used on space and not on time. So here I am treating "time" as "space" since I do not know what else to do.
So how to solve the above using NDSolve
(or NDSolveValue
) but using FEM?