Homework set #2, sections 1.3, 1.4, and 1.5

Clear["Global`*"]

p. 14, #3

yp=c/xp
xp=(x+y)/2
y=c/x
Simplify[(yp-xp)/(y-x)]

p. 20, #1, 2, 5, 6, 7

(* #1 *)
xhat=2.62
x=2.615
error[x_, xhat_]:=xhat-x
relativeError[x_, xhat_]:=error[x,xhat]/x
re=relativeError[x,xhat]
relativeError[Exp[x],Exp[xhat]]

(* #2 *)
xhat=1.4
(* x is in the interval [1.3,1.5] *)
{relativeError[1.5,xhat],relativeError[1.3,xhat]}
N[{-1/15,1/13}]

(* #5 *)
(* Log[10,2] approx w/10 *)
N[Log[10,2]]
N[3/10]

(* #6 *)
e1=(y1-y)
e2=(y2-y)
r1=e1/y
r2=e2/y
decimalsOfAccuracy[e_]:=-Log[10,e]
digitsOfAccuracy[re_]:=-Log[10,re]
Simplify[decimalsOfAccuracy[e2/3]-decimalsOfAccuracy[e2]]
N[%]
Simplify[digitsOfAccuracy[r2/3]-digitsOfAccuracy[r2]]

(* #7 *)
f[h_]:=1/(1-h)
fhat[h_]:=1+h*(1+h)
h=.21
hhat=.2
propogatedError[h_,hhat_]:=f[hhat]-f[h]
computationalError[h_,hhat_]:=fhat[hhat]-f[hhat]
totalError[h_,hhat_]:=computationalError[h,hhat]+propogatedError[h,hhat]

computationalError[h,hhat]
propogatedError[h,hhat]
totalError[h,hhat]

p. 28, 1, 4, 5, 8, 14

#1

a=100
ahat=100.1
b =101
gamma=1/180*Pi (* radians *)

relError[a_,ahat_]:=(ahat-a)/a
tableRowEntry[a_,ahat_]:={N[a],ahat,100*relError[a,ahat]}

TableForm[
{
tableRowEntry[a,ahat]
,tableRowEntry[b*Cos[gamma]-a,b*Cos[gamma]-ahat]
,tableRowEntry[(b*Cos[gamma]-a)^2,(b*Cos[gamma]-ahat)^2]
,tableRowEntry[(b*Cos[gamma]-a)^2+(b*Sin[gamma])^2,(b*Cos[gamma]-ahat)^2+(b*Sin[gamma])^2]
,tableRowEntry[Sqrt[(b*Cos[gamma]-a)^2+(b*Sin[gamma])^2],Sqrt[(b*Cos[gamma]-ahat)^2+(b*Sin[gamma])^2]]
},TableHeadings->{
{"a","b*Cos[gamma]-a","(b*Cos[gamma]-a)^2","(b*Cos[gamma]-a)^2+(b*Sin[gamma])^2","c"}
,{"true","approx","relError"}}
]

#4

Simplify[relError[Exp[x],Exp[x*(1+eps)]]]

#5

Clear[a,b,epsa,epsb,epsab]
ahat=a*(1+epsa)
bhat=b*(1+epsb)
abhat=a*b*(1+epsab)
Solve[abhat == ahat*bhat, epsab]
epsab=Replace[epsab,%][[1]]
epsab
epsa=.01
epsb=.02
epsab

#8: might start with some experiments:

b=Pi/2
f[x_]:=Abs[Cos[b+x]-Cos[b]]
Plot[{f[x],Abs[x]},{x,-Pi/2,Pi/2}]
g[x_]:=Cos[x]
condition[x_]:=Abs[x*g'[x]/g[x]]
Plot[condition[x],{x,-Pi/2,Pi/2}]

#8 is an opportunity to make use of the MVT from calculus: for example

Clear[b,e]
Integrate[-Sin[x],{x,b,b+e}]

Can you bound that integral?

#14, p. 30: assume a relative error in x of xhat=x(1+h). Looking at the  relative error in the Log function, we can simplify to get

Clear[x,h]

f[x_]:=Log[1+x*h/(1+x)]
g[x_]:=Log[1+x]
re[x_]:=f[x]/g[x]

Limit[Simplify[re[x]/h],h->0]

condition[x_]:=Abs[x*g'[x]/g[x]]
condition[x]

Plot[condition[x],{x,-1,8},PlotRange->{{-1,8},{0,10}}]