Homework 2.4: Tea time

pp. 75--, #1, 2, 4a-d, 5, 10, 11, 13, 22, 24, 26.

Exercise #1 and 2, p. 75

Exercises 4a-d, p. 75

4a
ans = 1.8294
4b
ans = 1.3977
4c
ans = 1.4788
4d
ans = 0.9484

Plot[{Exp[x]+2^(-x)+2*Cos[x]-6,Log[x-1]+Cos[x-1],2*x*Cos[x]-(x-2)^2},{x,0,4},
PlotLabels->Automatic,PlotRange->{-3,3}]

Exercise #5, pp. 75:

5a
ans = 1.8294
5b
ans = 1.3977
5c
ans = 1.4788
5d
ans = 0.9484

Exercise #10, pp. 75

Exercise 10
10a
10.151
8.4346

10a
0.5360
0.5722

f[x_]:=2Log[1+x^2]-x
x0=1;y0=f[x0];
x1=2;y1=f[x1];
x2=x1-y1*(x1-x0)/(y1-y0);
Show[
Plot[y1+(y1-y0)/(x1-x0)(x-x1),{x,0,3}],
ListPlot[{{x0,y0},{x1,y1},{x2,0}},PlotStyle->{Large}]
]

Exercise #11, pp. 75

Given my initial values, they both found the same roots. Newton just found them faster:

Newton: # of iterations: 5,5,6,7
Secant: # of iterations: 7,8,8,13

Exercise #13, pp. 75


x=0 will cause Newton’s to fail, because the derivative is 0 there.

f[x_]:=2+x-Exp[x]
Plot[{f[x],f'[x]},{x,-3,3}]

Exercise #22, pp. 76

x0=1;y0=0.3;
x1=1.1;y1=0.23;
x2=x1-y1*(x1-x0)/(y1-y0)
Show[
Plot[y1+(y1-y0)/(x1-x0)(x-x1),{x,0.5,2}],
ListPlot[{{x0,y0},{x1,y1},{x2,0}},PlotStyle->{Large}]
]

Exercise #24, pp. 76

p[x_]:=x^3-3x+3;
x0=-1;y0=p[x0];
x1=x0-p[x0]/p'[x0];
Show[
Plot[{p[x],y0+p'[x0](x-x0)},{x,-3,1}],
ListPlot[{{x0,y0},{x1,0}},PlotStyle->{Large}]
]

Exercise #26, pp. 76

x+y=20 
 (x+Sqrt[x])*(y+Sqrt[y])=172.2
 
 disp(“Exercise 26”);
f=@(x)(x + sqrt(x))*(20 - x + sqrt(20 - x)) - 172.2;
x0=9;
x1=9.3;
secant(f,x0,x1,10^(-4),20)

ans = 9.1496

f[x_]:=(x+Sqrt[x])*(20-x+Sqrt[20-x])-172.2
f'[x]
Simplify[f[x]]
Plot[f[x],{x,8,12}]
Solve[n1+n2==20 && (n1+Sqrt[n1])*(n2+Sqrt[n2])==172.2,{n1,n2}]