lin_fin_diff - M = N-1 STEP 2 for I = 2 M X = AA I*H A(I =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [y] = lin_fin_diff(tt,vv,kk,cc,zz,P,Q,R) f % % LINEAR FINITE-DIFFERENCE ALGORITHM 11.3 % % To approximate the solution of the boundary-value problem % % Y'' = P(X)Y' + Q(X)Y + R(X), A<=X<=B, Y(A) = ALPHA, Y(B) = BETA: % % INPUT: Endpoints A, B; boundary conditions ALPHA, BETA; % integer N, functions P, Q, and R. % % OUTPUT: Approximations W(I) to Y(X(I)) for each I=0,1,. ..,N+1. % % tt=a , vv=b, kk=alpha, cc=beta, zz= (number of intervals you want), functions % P, Q, and R % Change P,Q,R for different problems % zz = zz-1; z AA = tt; BB = vv; ALPHA = kk; BETA = cc; N = zz; % STEP 1 */ H = (BB-AA)/(N+1); A = zeros(1,N+1); B = zeros(1,N+1); C = zeros(1,N+1); D = zeros(1,N+1); L = zeros(1,N+1); U = zeros(1,N+1); Z = zeros(1,N+1); W = zeros(1,N+1); X = AA+H; A(1) = 2+H^2*Q(X); B(1) = -1+0.5*H*P(X); D(1) = -H^2*R(X)+(1+0.5*H*P(X))*ALPHA;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: M = N-1; % STEP 2 */ 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; % STEP 3 */ 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; % STEP 4 */ % STEPS 4 through 8 solve a tridiagonal linear system using % Crout factorization */ L(1) = A(1); U(1) = B(1)/A(1); Z(1) = D(1)/L(1); % STEP 5 */ 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; % STEP 6 */ L(N) = A(N)-C(N)*U(N-1); Z(N) = (D(N)-C(N)*Z(N-1))/L(N); % STEP 7 */ W(N) = Z(N); % STEP 8 */ for J = 1 : M I = N-J; W(I) = Z(I)-U(I)*W(I+1); end; I = 0; % STEP 9 */ for I = 1 : N X = AA+I*H; end; I = N+1; y=W;...
View Full Document

This note was uploaded on 09/19/2009 for the course MATH numerical taught by Professor Ford during the Spring '09 term at FAU.

Page1 / 2

lin_fin_diff - M = N-1 STEP 2 for I = 2 M X = AA I*H A(I =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online