finite difference method code
显示 更早的评论
% set domains limits and boundary conditions
xo = pi/2; xf = pi; yxo = 1; yxf = 1; N = 10;
% compute interval size and discrete x vector
dx = (xf-xo)/N; dx2 = dx*dx; x = (xo+dx):dx:xf;
% analytica solution (exact)
xe = linspace(xo,xf,N);
ye = (pi./(2*xe)).*(sin(xe) - 2*cos(xe));
% arranging the matrix a
%node 1
a(1,1)=dx2-2; a(1,2)=1+(dx/(xo+dx)); b(1)= ((yxo*dx) /(xo*dx))-yxo;
for i = 2:N-1
a(i,i-1) = (1-(dx/x(i)));
a(i,i) = dx2-2;
a(i,i+1) = (1+(dx/x(i)));
b(i)=0;
end
a(N,N-1)=(2*xf+2*dx)/xf; a(N,N-2)=-1; b(N)=yxf*dx2+yxf+((2*yxf*dx)/xf);
yi=a\b;
i keep getting the following error code
finite_1
Error using \
Matrix dimensions must agree.
Error in finite_1 (line 26)
yi=a\b
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!