Homework 4.1: Numerical Calculus

Andy Long, Spring, 2024

pp. 140--, #4, 5, 6, 7, 8, 9(a-d), 10(a-d), 11, 12, 17 

We did #4, 5, 6, and 7 together in class, so I’m not so worried about those. In addition, we did #17 together. So let’s look at the rest:

#8

Clear[f,x0,h]
FourOneFive[f_,x0_,h_]:=(f[x0+h]−f[x0−h])/(2h)
FourOneFive[f,x0,h]

FourOneFive[f,x0+h/2,h/2]

#9/10 (a-d)

FourOneSix[f_,x0_,h_]:=h/8640*(5257f[x0+6h]−5880f[x0+5h]+59829f[x0+4h]−81536f[x0+3h]+102459f[x0+2h]−50568f[x0+h]+30919f[x0])

9/10a:  Answer 20.32712878304436

f[x_]:=E^x
{a,b}={-4,3};
h=(b-a)/7.0;
nineA=FourOneSix[f,a+h,h]
Integrate[f[x],{x,a,b}]
nineAexact=N[%]
Abs[nineA-nineAexact]

9b:

f[x_]:=Sin[x]
{a,b}={-1,6};
h=(b-a)/7.0;
nineB=FourOneSix[f,a+h,h]
Integrate[f[x],{x,a,b}]
nineBexact=N[%]
Abs[nineB-nineBexact]

9c:

f[x_]:=1/(x-5)
{a,b}={10,17};
h=(b-a)/7.0;
nineC=FourOneSix[f,a+h,h]
Integrate[f[x],{x,a,b}]
nineCexact=N[%]
Abs[nineC-nineCexact]

9d:

f[x_]:=(x^5-4)
{a,b}={-4,3};
h=(b-a)/7.0;
nineD=FourOneSix[f,a+h,h]
Integrate[f[x],{x,a,b}]
nineDexact=N[%]
Abs[nineD-nineDexact]

#11

FourOneFour[f_,x0_,h_]:=(−2f[x0−h]+f[x0]+f[x0+h])/(3h)
f[x_]:=(x-1)^2Sin[x]
elevenExact=f'[0]

11/12a:

h=1.0;
elevenA=FourOneFour[f,h/6,h]
Abs[elevenA-elevenExact]

11/12b:

h=0.5;
elevenB=FourOneFour[f,h/6,h]
Abs[elevenB-elevenExact]

11/12c:

h=0.25;
elevenC=FourOneFour[f,h/6,h]
Abs[elevenC-elevenExact]

11/12d:

h=0.125;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]

Just getting better and better and better with decreasing h!

h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]
h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]
h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]
h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]
h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]
h=h/2;
elevenD=FourOneFour[f,h/6,h]
Abs[elevenD-elevenExact]