Use of Initial Condition for a First Order Finite Difference Scheme

1 回表示 (過去 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 Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by