You are on page 1of 10

Garrett Knapp!

MAE 384 Ballesteros!


2/25/14!

MAE 384 HW #4!


!

!
!

1) [(20*40*120)(8)]/(1024)^2!

!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!

0.7324 mb!

!
!
!
!
!
!
!
!
!
!

2)!
Script:!
format long!
f= @(x) 0.99403+x*1.671*10^(-4)+x.^2*9.7215*10^(-8)x.^3*9.5838*10^(-11)+x.^4*1.9520*10^(-14)-1.2!
x=linspace(0,2000)!
plot(x,f(x))!

!
!

true=fzero(f,1000);!
x_l=0;!
x_u=2000;!
n=0;!

while f(x_l)*f(x_u)<0!
x_m=(x_l+x_u)/2;!
if f(x_m)*f(x_u)<0!
x_l=x_m;!
else x_u=x_m;!
end!
n=n+1;!
error=(true-(x_m))/(true)*100;!

!
end!
!

error!
x_m!
true!

!
Output:!
!
error =!
!
8.077147654298140e-14!
!
!
x_m =!
!

1.126009750841874e+03!

!
!
true =!
!
1.126009750841875e+03!
!
!
!
!
!

3)!
Function:!
function [ x ] = gausselim( A,b )!
[dim]=size(A)!
A=[A,b]!
row=1;!
col=1;!
s=[dim(1,1), dim(1,2)];!
z=1;!
y=1;!
n=1;!
while col<=dim(1,2)&&n<3!
max_val=max(A(:,col),[],1)!
[I,J]=ind2sub(s,max_val)!
index=[I,J]!
[rounded]=round(index)!
A([rounded(1,1) row],:)= A([row rounded(1,1)],:)!
while(z)<3!
ratio=A(z+1,col)/(max_val)!
A(z+1,:)=A(z+1,:)-ratio*A(y,:)!
z=z+1!
end!
col=col+1;!
row=row+1;!
z=row;!
y=y+1;!
n=n+1!
end!
x_1=A(3,3)/A(3,4)!
x_2=(A(2,4)-(x_1)/5)/6.2!
x_3=(A(1,4)-2*(x_1+x_2))/5!
x=[x_1 x_2 x_3]!
end!

!
Output:!
!
x =!
!

1.000000000000000 1.000000000000000 1.000000000000000!

!
!
!
!
!
!
!
!
!
!

4)!
Script:!
%% Solving the system of Equations!
A=[1 7 -4;4 -4 9;12 -1 3]!
B=[-51;62;8]!
f_21=A(2,1)/A(1,1);!
A(2,:)=A(2,:)-4*A(1,:)!
f_31=A(3,1)/A(1,1);!
A(3,:)=A(3,:)-12*A(1,:)!
f_32=A(3,2)/A(2,2);!
A(3,:)=A(3,:)-f_32*A(2,:)!
U=A!
L=[1 0 0;f_21 1 0;f_31 f_32 1]!

y_1=(B(1,1))/(L(1,1));!
y_2=B(2,1)-4*y_1;!
y_3=B(3,1)-(85/32)*y_2-12*y_1;!
y=[y_1;y_2;y_3]!

x_3=y(3,1)/U(3,3);!
x_2=(y(2,1)-U(2,3)*x_3)/U(2,2);!
x_1=(y(1,1)-U(1,3)*(x_3)-U(1,2)*x_2)/U(1,1);!

!
x=[x_1;x_2;x_3]!
!

%% Finding the Inverse!


Z=[]!
z=[]!
for j=1:3!
I=[1 0 0;0 1 0;0 0 1];!
z_1=I(1,j)/L(1,1);!
z_2=(I(2,j)-L(2,2))/L(2,1);!
z_3=(I(3,j)-L(3,1)*z_1-L(3,2)*z_2)/L(3,3);!
Z=[z;z]!
z=[z_1;z_2;z_3]!

!
end!
!
!

Output:!

!
x =!
!

-1.064908722109532!
-3.922920892494929!
5.618661257606491!

!
z =!
!

1.000000000000000!
-0.250000000000000!
-11.335937500000000!

!
!
z =!
!

0!
0!
0!

!
!
z =!
!

0!
-0.250000000000000!
1.664062500000000!

!
(These three columns create the inverse matrix but I was unable to concatenate them)!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!

!
!
!
!
!
!
!
!
!
!
5)!
!

Script:!
A=[8 2 1;3 7 2;2 3 9]!
f_21=A(2,1)/A(1,1);!
A(2,:)=A(2,:)-f_21*A(1,:)!
f_31=A(3,1)/A(1,1);!
A(3,:)=A(3,:)-f_31*A(1,:)!
f_32=A(3,2)/A(2,2);!
A(3,:)=A(3,:)-f_32*A(2,:)!
U=A!
L=[1 0 0;f_21 1 0;f_31 f_32 1]!

!
detA=L(1,1)*L(2,2)*L(3,3)*U(1,1)*U(2,2)*U(3,3)!
!
Output:!
!
U =!
!

8.000000000000000 2.000000000000000 1.000000000000000!


0 6.250000000000000 1.625000000000000!
0
0 8.100000000000000!

!
!
L =!
!

1.000000000000000
0
0!
0.375000000000000 1.000000000000000
0!
0.250000000000000 0.400000000000000 1.000000000000000!

!
!
detA =!
!
405!
!
!
!
!
!

!
!
!
!
!
!
!
!
!
!
6)!
!

Script:!
format long!
A=[1 4 9 16 25;4 9 16 25 36; 9 16 25 36 49; 16 25 36 49 64;25 36 49 64 81];!
I=[1 0 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 0 1 0;0 0 0 0 1];!
B=[A I];!
rsum=[];!
for i=1:5!
j=sum(A(i,:));!
rsum=[rsum j];!
end!

!
row_sum_norm=max(rsum)!
!
B(2,:)=B(2,:)-4*B(1,:);!
B(3,:)=B(3,:)-9*B(1,:);!
B(4,:)=B(4,:)-16*B(1,:);!
B(5,:)=B(5,:)-25*B(1,:);!

!
B(2,:)=(-1/7)*B(2,:);!
!

for i=3:5!
B(i,:)=B(i,:)-(B(i,2))*B(2,:);!
end!

B(3,:)=(1/B(3,3))*B(3,:);!
for i=4:5!
B(i,:)=B(i,:)-(B(i,3))*B(3,:);!
end!

B(4,:)=(1/B(4,4))*B(4,:);!
B(5,:)=B(5,:)-B(5,4)*B(4,:)!

!
!

Output:!
row_sum_norm =!

255!

!
!
B =!
!
1.0e+14 *!
!
Columns 1 through 4!
!

0.000000000000010 0.000000000000040 0.000000000000090 0.000000000000160!


0 0.000000000000010 0.000000000000029 0.000000000000056!
0
0 0.000000000000010 0.000000000000030!
0
0
0 0.000000000000010!
0
0
0
0!

!
Columns 5 through 8!
!

0.000000000000250 0.000000000000010
0
0!
0.000000000000091 0.000000000000006 -0.000000000000001
0!
0.000000000000060 0.000000000000021 -0.000000000000025 0.000000000000009!
0.000000000000020 -0.351843720888319 1.055531162664959 -1.055531162664960!
0 -0.000000000000010 0.000000000000020
0!

!
Columns 9 through 10!
!

0
0!
0
0!
0
0!
0.351843720888320
0!
-0.000000000000020 0.000000000000010!

!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!

!
!
!
!
!
!
!
!
!
!
7)!
!

Command Window:!
%%11.1 Gauss-Siedel!
format long!
A=[10 2 -1; -3 -6 2; 1 1 5]!
b=[27; -61.5; -21.5]!
x_1=0.000000001;!
x_2=0;!
x_3=0;!
x_test=1;!
n=0;!
error=1;!

while error>0.05!
x_test=x_1!
x_1=(b(1,1)-A(1,2)*x_2-A(1,3)*x_3)/A(1,1);!
x_2=(b(2,1)-A(2,1)*x_1-A(2,3)*x_3)/A(2,2);!
x_3=(b(3,1)-A(3,1)*x_1-A(3,2)*x_2)/A(3,3);!
error=abs(x_1-x_test)/(x_1)*100;!
n=n+1;!
end!

x=[x_1;x_2;x_3]!
error!

!
Output:!
!
x =!
!

0.500002685132801!
8.000001273515309!
-6.000000791729622!

!
!
error =!
!
0.006484928573989!
!

!
!
!
!
!
!
!
!

You might also like