Question
please slove this question in MATLAB and explain clearly about it. Many thanks.
Question 3. Given the following boundary-value problem Use the finite difference method to solve the problem with h 0.02. Plo
0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for solving Finite difference method ode clear all close all %creating tridiagonal matrix dt-0.02; a_ @ ( tt ) (2,,움各各움움各各움움各움움움各各움움各움 End of Code 各各各各各各움음움움움움움움움움움움움음 The solution vector for y- 0.911117026058629 0.829767525825777 0.75553y(t) vs. t plot using finite difference method for h-0.02 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.1 02 034 0.5 06 07 00.91 Publ

%%Matlab code for solving Finite difference method ode
clear all
close all
%creating tridiagonal matrix
dt=0.02;
a=@(tt) (2-(8*tt+1)*dt); b=@(tt) (2*(dt^2)*(-(16+tt.^2))-4); c=@(tt) (2+(8*tt+1)*dt);
r=@(tt) (-12)*tt.^2;
%tridiagonal matrix of size n=((2-0)/dx)-1;
%all initial conditions
t_in=0; t_fnl=1;
y_in=1; y_end=0;

t=t_in:dt:t_fnl;
%number of steps
n = ((t_fnl-t_in)/dt)-1;
%Tridiagonal matrix
%A=full(gallery('tridiag',n,a,b,c));
A=zeros(n,n);
for i=2:n-1
    A(i,i)=b(t(i));
    A(i,i+1)=c(t(i));
    A(i,i-1)=a(t(i));

end
A(1,1)=b(t(1));
A(1,2)=c(t(1));
A(n,n-1)=a(t(n));
A(n,n)=b(t(n));

for i=2:n
    bb(i,1)=(2*dt^2*r(t(i)));
end
bb(1,1)=bb(1,1)-a(t(1))*y_in;
bb(n,1)=bb(n,1)-c(t(n))*y_end;
%solving using backslash operator
%all u values
y_val=A\bb;
yy(1)=y_in;
for i=2:n+1
    yy(i)=y_val(i-1);
end
yy(n+2)=y_end;
%all x value
xx=t_in:dt:t_fnl;
plot(xx,yy,'Linewidth',2 )
xlabel('t')
ylabel('y(t)')
title('y(t) vs. t plot using finite difference method for h=0.02')

fprintf('The solution vector for y=\n')
disp(yy')
%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
please slove this question in MATLAB and explain clearly about it. Many thanks. Question 3. Given the following boun...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT