フィルターのクリア

FDM by centred difference gives a gradient of -0.5 instead of -2

2 ビュー (過去 30 日間)
Eustace Tan
Eustace Tan 2014 年 5 月 2 日
Okay, maybe I'm just stupid, but the title pretty much says it all. The code I made is as follows,
n=[10:10:90 100:100:900 1000:1000:9000 10000:10000:90000];
for i=1:length(n),
h(i)=1/(n(i));
E=sparse(1:n(i)+1,1:n(i)+1,2*ones(1,n(i)+1),n(i)+1,n(i)+1);
F=sparse(2:n(i)+1,1:n(i),-1*ones(1,n(i)),n(i)+1,n(i)+1);
A=F+E+F';
A(1,1)=1;
A(1,2)=0;
A(n(i)+1,n(i))=-1;
A(n(i)+1,n(i)+1)=1;
x=0:h(i):1;
B(1,1:1+n(i))=((h(i))^2)*10;
B(1,1)=0;
B(1,1+n(i))=0;
u=A\B';
y=-5*x.^2+10*x; %Analytical solution
e(i)=norm(u-y');
end
figure
loglog(h.^-2,e,'r-+')
grid on
title('Graph of partition width to the power of -2, h^-^2 versus error, e')
xlabel('partition width to the power of -2, h^-^2')
ylabel('error, e')
I have been hammering away at this all night but can't seem to figure out why the gradient is -0.5. Any help?

回答 (0 件)

カテゴリ

Help Center および File ExchangeOceanography and Hydrology についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by