Homework Assignment #3

# Homework Assignment - 1.2500 2 clear all n = 50 h = 1/n for i = 1:n A(i =(2 h^2(pi^2/h^2 end for i = 1:n-1 B(i =-1/h^2 end for i = 1:n-1 C(i

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

1. n = input('Dimension of n of matrix:'); A = input('Center diagonal vector of length n:'); B = input('Upper Diagonal vector of length n-1:'); C = input('Lower Diagonal vector of length n-1:'); R = input('Right hand side of length n:'); B=[0,B]; L(1, 1) = A(1); U(1, 2) = C(1)/L(1, 1); Z(1) = R(1)/L(1, 1); for i = 2:n-1 L(i, i-1) = B(i); L(i, i) = A(i) - (L(i, i-1)) * (U(i-1, i)); U(i, i+1) = C(i)/L(i, i); Z(i) = (R(i)-L(i, i-1)*Z(i-1))/L(i, i); end L(n, n-1) = B(n); L(n, n) = A(n) - L(n, n-1)*U(n-1, n); Z(n) = (R(n) - L(n, n-1)*Z(n-1))/L(n, n); x(n) = Z(n); for i = n-1:-1:1 x(i) = Z(i) - (U(i,i+1) * x(i+1)); end disp('x =') disp(x) >> Crout Dimension of n of matrix:4 Center diagonal vector of length n:[2, 2, 2, 2] Upper Diagonal vector of length n-1:[-1, -1, -1] Lower Diagonal vector of length n-1:[-1, -1, -1] Right hand side of length n:[1, 0, 0, 1] x = 1.0000 1.0000 1.0000 1.0000 >> U U = 1 -0.5000 0 0 0 1 -0.6667 0 0 0 1 -0.7500 0 0 0 1 >> L L = 2.0000 0 0 0 -1.0000 1.5000 0 0 0 -1.0000 1.3333 0 0 0 -1.0000

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1.2500 2. clear all n = 50; h = 1/n; for i = 1:n A(i) = (2+h^2*(pi^2))/h^2; end for i = 1:n-1 B(i) = -1/h^2; end for i = 1:n-1 C(i) = -1/h^2; end for i = 1:n R(i) = 2*(pi^2)*sin(pi*i/n); end B=[0,B]; L(1, 1) = A(1); U(1, 2) = C(1)/L(1, 1); Z(1) = R(1)/L(1, 1); for i = 2:n-1 L(i, i-1) = B(i); L(i, i) = A(i) - (L(i, i-1)) * (U(i-1, i)); U(i, i+1) = C(i)/L(i, i); Z(i) = (R(i)-L(i, i-1)*Z(i-1))/L(i, i); end L(n, n-1) = B(n); L(n, n) = A(n) - L(n, n-1)*U(n-1, n); Z(n) = (R(n) - L(n, n-1)*Z(n-1))/L(n, n); x(n) = Z(n); for i = n-1:-1:1 x(i) = Z(i) - (U(i,i+1) * x(i+1)); end x y = x; plot(0:1*pi/50:49*pi/50,y) N = 50 π HW 4 Ian Chang Valentine’s Day 2008 7223076 N = 100 π 3. First you should check that your method converges. If your method converges then you need to go ahead and check the rate of convergence. Also if there is any data that you can use to check your method against, you should do that as well....
View Full Document

## This note was uploaded on 05/01/2009 for the course PSTAT 120A taught by Professor Mackgalloway during the Spring '08 term at UCSB.

### Page1 / 2

Homework Assignment - 1.2500 2 clear all n = 50 h = 1/n for i = 1:n A(i =(2 h^2(pi^2/h^2 end for i = 1:n-1 B(i =-1/h^2 end for i = 1:n-1 C(i

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

View Full Document
Ask a homework question - tutors are online