Homework 3

# Homework 3 - EGM 3344 Sorting Number 190 Problem Set 3...

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

EGM 3344 Sorting Number: 190 Problem Set: 3 Problems completed: 4.1, 4.3, 4.4, 4.7, 4.12, 4.15, 4.21, 5.8hand, 5.8, 5.13, 6.1, 6.4hand, 6.4, 6.13, 6.23

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

View Full Document
Problem 4.3 Code and Solution: %Problem 4.3 %Calculate the machine epsilon E E = 1; while (1 + E)>1 E = E/2; end E = 2*E EDU>> macheps E = 2.2204e-016 EDU>> eps ans = 2.2204e-016
Problem 4.4 Code and Solution: %Problem 4.4 %Find the smallest positive real number used in MATLAB x = 1; xnew = 1; while xnew > 0 xnew = x / 2; if xnew ~= 0 x = xnew; end end x EDU>> Chapra4_4 x = 4.9407e-324

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

View Full Document
Problem 4.15 Code and Solution: %Problem 4.15 xi = 2; h = 0.2; xiplus1 = 2.2; ximinus1 = 1.8; f1 = [25 -6 7 -88]; fxi = polyval(f1,xi); fxiplus1 = polyval(f1,xiplus1); fximinus1 = polyval(f1,ximinus1); f2 = [75 -12 7]; true = polyval(f2,xi) format short %Foward Difference Foward = (fxiplus1 - fxi)/h Et = abs(true - Foward) %Backward Difference Backward = (fxi - fximinus1)/h Et = abs(true - Backward) %Centered Difference Centered = (fxiplus1 - fximinus1)/(2*h) Et = abs(true - Centered) true = 283 Foward = 312.8000 Et = 29.8000 Backward = 255.2000 Et = 27.8000 Centered = 284.0000 Et = 1.0000
Problem 4.21 Code and Solution: %Problem 4.21 function Chapra4_21(func,dfunc,x,n) format long dftrue = dfunc(x); h = 1; H(1) = h; D(1) = (func(x+h) - func(x-h))/(2*h); E(1) = abs(dftrue - D(1)); for i = 2:n h = h/10; H(i) = h; D(i) = (func(x+h) - func(x-h))/(2*h); E(i) = abs(dftrue - D(i)); end L = [H' D' E']'; fprintf( ' step size finite difference true error\n' ); fprintf( '%14.10f %16.14f %16.13f\n'

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.

{[ snackBarMessage ]}

### Page1 / 12

Homework 3 - EGM 3344 Sorting Number 190 Problem Set 3...

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

View Full Document
Ask a homework question - tutors are online