Use of Initial Condition for a First Order Finite Difference Scheme

4 visualizaciones (últimos 30 días)
Hi Folks,
I am studying some matlab code to understand finite difference schemes of first order. I found this bit of script online which works but I dont understand what role the boundary conditions play because if i delete the BC's, the script still plots a graph....
N = 2000;
t = linspace(0,1,N)';
dt = t(2) - t(1);
% Create the first derivative operator
D1 = diag(ones(N,1));
D2 = diag(-ones(N,1),-1);
D2 = D2(1:N,1:N);
D = (D1+D2)/dt;
% Write it as M*y = f
M = [diag(t)*D + diag(1+sin(10*t))];
f = cos(t);
% Add boundary conditions
% f(1) = 1;
% M(1,:) = 0;
% M(1,1) = 1;
%Solve and plot
y = M\f;
plot(t,y,'r');
hold on;
Any information appreciated. Regards

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by