Reputation: 2445
I am trying to implement these formulas:
this is what I have tried:
x_new = (speye(nv)+ dt * lambda * L) * x_old;
Is there anything wrong with this? How can I calculate this using sparse operation?
I have tried this:
x_new = (speye(nv)- dt * lambda * L) \ x_old;
How to implement the backward part where the existing x
is calculated based on the new x
? Is it OK to use division?
L
is a sparse matrix like this:
full(L) =
-1.0000 0.2500 0.2500 0.2500 0.2500
0.3333 -1.0000 0.3333 0 0.3333
0.3333 0.3333 -1.0000 0.3333 0
0.3333 0 0.3333 -1.0000 0.3333
0.3333 0.3333 0 0.3333 -1.0000
also for other variable we have something like this:
nv = 5;
dt = 0.01;
lambda = 0.5;
x_old = [-4 0 5;
1 -5 5;
1 0 1;
1 5 5;
1 0 0]
Upvotes: 0
Views: 1123
Reputation: 8007
I don't see the domain here but the Backward Euler method is a basic ordinary differential equation solver.
There are two approaches how to solve the situation when x_new
stands on both sides of the equation.
You use x_new_temp
and you set x_new_temp
as x_old
for the first iteration and do few iterations with the Forward Euler formula. After the iterations perhaps limited by some difference between x_new_temp
from iteration i
and i-1
, you set x_new
as x_new_temp
from the last iteration.
The Backward Euler formula dictates:
y_new = y_old + k*f(t,y_old)
We can transform this into:
y_old + k*f(t,y_old) - y_new = 0
This is a basic non-linear function which can be solved with any numerical method intended to solve this type of problem.
In your case when matrix are involved, I would go with the fixed point iteration.
Upvotes: 1