Use of Initial Condition for a First Order Finite Difference Scheme

조회 수: 4 (최근 30일)
bugatti79
bugatti79 2014년 7월 20일
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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by