finite difference method code
Show older comments
% 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
Accepted Answer
More Answers (0)
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!