Write Matlab Code For Solving This BVP Using Finite Different Method
Write Matlab Code For Solving This BVP Using Finite Different Method
for i = 2 : m
x = aa+i*h;
a(i) = 2+h^2*q(x);
b(i) = -1+0.5*h*p(x);
c(i) = -1-0.5*h*p(x);
d(i) = -h^2*r(x);
end
x = bb-h;
a(n) = 2+h^2*q(x);
c(n) = -1-0.5*h*p(x);
d(n) = -h^2*r(x)+(1-0.5*h*p(x))*beta;
l(1) = a(1);
u(1) = b(1)/a(1);
z(1) = d(1)/l(1);
for i = 2 : m
l(i) = a(i)-c(i)*u(i-1);
u(i) = b(i)/l(i);
z(i) = (d(i)-c(i)*z(i-1))/l(i);
end
l(n) = a(n)-c(n)*u(n-1);
z(n) = (d(n)-c(n)*z(n-1))/l(n);
w(n) = z(n);
for j = 1 : m
i = n-j;
w(i) = z(i)-u(i)*w(i+1);
end
i = 0;
fprintf('%5.4f %11.8f\n', aa, alpha);
for i = 1 : n
x = aa+i*h;
fprintf('%5.4f %11.8f\n', x, w(i));
end
i = n+1;
fprintf('%5.4f %11.8f\n', bb, beta);
*Write a Matlab program by the method with spatial step size: h=0.1, and time step
size: k=0.002;
%view(60,-120);
view(80,30)
axis([xl xr yb yt -1 1])
Solve the problem by the finite difference method with (space step size) and or small enough
to satisfy the CFL condition; 0.05 h k= h / c
Use Matlab’s mesh command to plot the approximate solutions and the exact solution.