Converting a 2nd order differential equation to a system of algebraic equations, and forming a matrix

3 views (last 30 days)
Hello,
We are given the equation: 0 = Dd^2x/dx^2 - Udc/dx - kc, where D = 2, U = 1, and k = 0.2, and where x goes from 0 to 10 with a step size of 0.1, c(0) = 80, and c(10) = 10. I'm supposed to develop a plot of c vs. x, but I'm not sure how to convert the given differential equation to a system of algebraic equations and then set up a coefficients matrix in MATLAB. I believe that the coefficients matrix should be of length 101x101, as there are 101 values between 0 and 10 with a step size of 0.1 (including 0 and 10). A peer assisted me with the code below, but I'm having trouble following how they were able to know what each of the three coefficients of the three diagonals of the tridiagonal matrix were. Here is the code:
D=2; U=1; A=zeros(99);
A(1,:) = [100*(U-2*D) 10*(D-U) zeros(1,97)];
A(99,:) = [zeros(1,97) D 100*(U-2*D)];
B = zeros(99,1);
for i=2:98
A(i,:)=[zeros(1,i-2) D 100*(U-2*D) 10*(D-U) zeros(1,98-i)];
end
B(1,1) = -D*80;
B(99,1) = -D*200 + U*10;
C = A\B;
plot(C)
In conclusion, my question is, how can I convert the given differential equation to a system of algebraic equations, and then using them in MATLAB, how can I create a coefficients matrix, A, and a product matrix, B, so that I can determine the unknowns matrix, C, using C = A/B?

Answers (0)

Categories

Find more on Linear Algebra 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!