Question

Write a MATLAB code to solve below 2nd order linear ordinary differential equation by finite difference method: y-y-0 in do

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please refer to the matlab script bvpSolver.m at the end. Run the script to generate the required plot, the screen shot of the code and the plot are also attached at the end.

Such that y( 1)--1 and y (x -1) - 1 The second order approximation to y and y respectively are 2y; +yi- and (Ax)2 2(4x) SuI=¼ 2, 3, , 40 except the end nodes i=1 and 41. Now, use boundary conditions associated with nodes i and 41, 2 4x ~-3 yi + 4yLikewise, for i=40 24 Δχ 4 D Rewrite in matrix form the system of equations 4 (2+A2) -4 (2+5%) (2-AX) 4- 24 BX 40X 40 520% y2so, the matrix equation is Ay=b and Later calculations and plots are shown in the Matlab.

bvpSolver.m

clear, close all; clc;

a = -1 ;
b = 1 ;
dx = 0.05 ;
numIntervals = ( b - a ) / dx ;
numNodes = numIntervals + 1 ;

e0 = (2 + dx) * ones( numNodes-1, 1 ) ;
e1 = -4 * ones( numNodes-1, 1 ) ;
e2 = (2 - dx) * ones( numNodes-1, 1 ) ;
A = spdiags( [e0, e1, e2], -1:1, numNodes-1, numNodes-1 ) ;
A(1, 1) = 3; A(1, 2) = -4; A(1, 3) = 1;

b = zeros( 1, numNodes-1 );
b(1) = 2 * dx ;
b(end) = -(2 - dx) ;

y = A\b' ;

yAll = [ y; 1 ];
xAll = a + (0 : numNodes-1) * dx ;
yTrue = 1 + exp(2) - exp(xAll + 1);

plot( xAll, yAll, 'o', xAll, yTrue, '-' )
xlabel( '\bf x' )
ylabel( '\bf y' )
legend( 'numerical', 'analytical' )
grid on
grid minor

O numerical analytical 4 0.5 0.5Name 1-clear, close all; clc; 40x40 sparse do... 1x40 double 0.0500 40x1 double 40x1 double 40x1 double 3- a=-1; 4-b=1; 5- dx

Add a comment
Know the answer?
Add Answer to:
Write a MATLAB code to solve below 2nd order linear ordinary differential equation by finite difference method: y"-y'-0 in domain (-1, 1) with boundary condition y(x-1)--1 and y(x-1)-1. with...
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