Assignment 2

# Assignment 2 - B Ian Chang 7223076 HOMEWORK 3 enter...

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

CODE: clear all clc A = input('enter original matrix A='); b = input('enter matrix b ='); [n,n] = size(A); for p = 1:n max = p; for i = p+1 : n if abs(A(i,p)) > abs(A(max,p)) max = i; end end A([p max], :) = A([max p], :); b([p max], :) = b([max p], :); for i = p+1:n alpha = A(i,p)/A(p,p); b(i, :) = b(i, :) - alpha*b(p, :); A(i, :) = A(i, :) - alpha*A(p, :); end end x = zeros(size(b)); for i = n: -1 : 1 j = i + 1 :n; x(i, :) = (b(i, :) - A(i,j) * x(j, :)) / A(i,i); end 5. A.) enter original matrix A=[1 -1 3; 3 -3 1; 1 1 0] enter matrix b =[2; -1; 3] >> x x = 1.1875 1.8125 0.8750 One row interchange.

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: B.) Ian Chang 7223076 HOMEWORK 3 enter original matrix A=[2 -1.5 3; -1 0 2; 4 -4.5 5] enter matrix b =[1; 3; 1] >> x x =-1 1 0 row interchanges. C.) enter original matrix A=[2 0 0 0; 1 1.5 0 0; 0 -3 .5 0; 2 -2 1 1] enter matrix b =[3; 4.5; -6.6; .8] >> x x = 1.5000 2.0000-1.2000 3.0000 0 row interchanges. D.) enter original matrix A=[1 1 0 1; 2 1 -1 1; 4 -1 -2 2; 3 -1 -1 2] enter matrix b =[2; 1; 0; -3] Warning: Divide by zero. No unique solution can’t divide by zero. 6. A.) alpha = -1 B.) C.)...
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

Assignment 2 - B Ian Chang 7223076 HOMEWORK 3 enter...

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

View Full Document
Ask a homework question - tutors are online