資源簡介
求微分方程中兩點邊值問題的追趕赴,參考微分方程數值解
代碼片段和文件信息
function??a=ejcf(N)
format?long
h=pi/N;?x=h*[0:N];??
U=@(m)(m*h+2*sin(m*h));??%真解
b=(h^2-2).*ones(N-11);?%差分形式
a=zeros(N-21);
c=zeros(N-21);
for?i=2:N-1
a(i-1)=1+(h^2/2)*i;?
end
for?j=1:N-2
c(j)=1-(h^2/2)*j;
end
A=diag(b)+diag(a-1)+diag(c1);???%三對角矩陣(n-1)*(n-1)
f=@(m)(h^3.*(-2.*m.*cos(m.*h)));??
u0=0;un=pi;?%邊值
f1=f(1)-(1+h/2)*u0;f_=f(N-1)-(1-(N-1)*h^2/2)*un;
ff=[f1f(2:N-2)f_];
u1=zgf(Aff)‘;
ue=[u0u1un];???%數值解
u=[U(0:N)];???%真解
er=abs(u-ue);
figure(1)
plot(xu‘r*‘xue‘.‘)?%畫圖
legend(‘真解‘‘差分解‘‘Location‘‘best‘);?%英文是把前面漢字放在合適位置
figure(2)
semilogy(xer‘*‘)
- 上一篇:掌紋有效區域提取
- 下一篇:matlab33節點程序代碼
評論
共有 條評論