Project 3 Solutions

# Project 3 Solutions - Project 3 Group name Unknowns Group...

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

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

View Full Document

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: Project 3 Group name: Unknowns Group members: Annon, Sofia, Hristian, Divya 1. Matlab code: function [L,U]=mylu(A) m=size(A,1); U=A; L=eye(m); for i=1:m-1 for j=i+1:m a=-U(j,i)/U(i,i); U(j,:)=a*U(i,:)+U(j,:); L(j,i)=-a; end end >> A=rand(5) A = 0.2028 0.0153 0.4186 0.8381 0.5028 0.1987 0.7468 0.8462 0.0196 0.7095 0.6038 0.4451 0.5252 0.6813 0.4289 0.2722 0.9318 0.2026 0.3795 0.3046 0.1988 0.4660 0.6721 0.8318 0.1897 >> [L,U]=mylu(A) L = 1.0000 0 0 0 0 0.9801 1.0000 0 0 0 2.9778 0.5461 1.0000 0 0 1.3424 1.2453 0.9402 1.0000 0 0.9805 0.6163 0.0073 0.3323 1.0000 U = 0.2028 0.0153 0.4186 0.8381 0.5028 0 0.7318 0.4359 -0.8018 0.2167 0 0 -0.9595 -1.3767 -1.1867 0 0.0000 0 1.5472 0.4756 0 0.0000 0 0 -0.5863 >> A-L*U ans = 1.0e-015 * 0 0 0 0 0 0 0 0 -0.0486 0 0 0 0 0 0.3331 0 0 -0.0278 0.1110 0 0 0 0 0.1110 -0.0278 We can see that L is lower triangular and that U is upper triangular and that L*U does equal A because the exponent is extremely small. >> A=magic(5) A = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 >> [L,U]=mylu(A) L = 1.0000 0 0 0 0 1.3529 1.0000 0 0 0 0.2353 -0.0128 1.0000 0 0 0.5882 0.0771 1.4003 1.0000 0 0.6471 -0.0899 1.9366 4.0578 1.0000 U = 17.0000 24.0000 1.0000 8.0000 15.0000 0 -27.4706 5.6471 3.1765 -4.2941 0 0 12.8373 18.1585 18.4154 0 0 0 -9.3786 -31.2802 0 0 0 0 90.1734 >> A-L*U ans = 1.0e-014 * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3553 0 0 0 0 0 0 0 0.3553 0 0 We can see again in this example that L is lower triangular and that U is upper triangular and that L*U does equal A because the exponent is extremely small.--------------------------------------------------------------------------------------------------------------------------------------- 2. function [x,count] = ppmysolve(A,b) m = size(A,1); n = size(A,2); x = zeros(n,1); count=0; %Bad Gauss code A=[A b]; for i=1:m-1 [r,k]=max(abs(A(i:m,i))); if (k ~= 1) count=count+1; temp=A(i+k-1,:); A(i+k-1,:)=A(i,:); A(i,:)=temp; end for j=i+1:m A(j,:)=A(j,:)-(A(j,i)/A(i,i))*A(i,:); end end b = A(:,n+1); B = A(1:m,1:n); %x = backsub(B,b); for i=n:-1:1 x(i)=(b(i)-B(i,:)*x)/B(i,i); end--------------------------------------------------------------------------------------------------------------------------------------...
View Full Document

## This note was uploaded on 09/10/2008 for the course MAD 4401 taught by Professor Martcheva during the Spring '08 term at University of Florida.

### Page1 / 23

Project 3 Solutions - Project 3 Group name Unknowns Group...

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

View Full Document
Ask a homework question - tutors are online