#hw2.txt: Jan 31, 2014. Katie McKeon Help:=proc() print(`Hd1(f,d,x,x0) Hd(f,d,x,x0,N)`): print(`TestHouseholder(f,d,x,x0,eps,N)`): end: read`C2.txt`: #Examples from Garvan's Maple Book #data types f:=x^2-1: L:=seq(f, x=1..6); S:={L}; M:=[L]; F:=array(1..2,1..3,[[1,2,3],[5,9,7]]); #Calculus h:=unapply(f,x); X:=[seq(evalf(i^(1/2)), i=1..6)]; Y:=map(h,X); Sum(f, x=1..6); Limit((x^2-4)/(x^2-2),x=infinity); value(%); G:=int(x^4/(1-x^10)^(1/2),x); diff(%,x); #Hd1(f,d,x,x0) takes a function f in the variable x #a derivative order d, and an initial guess x0 #and calculates the first iteration of Householder's method #to approximate a zero of f Hd1:=proc(f,d,x,x0) local g: g:= x+d*normal(diff(1/f, [x$d-1])/diff(1/f, [x$d])): subs(x=x0, g): end: #Hd(f,d,x,x0,N) performs N iterations of Householder's method #with derivative order d for a function f in variable x #where x0 is the initial guess of the zero Hd:=proc(f,d,x,x0,N) local x1,i: x1:=x0: for i from 1 to N do x1:=Hd1(f,d,x,x1): od: x1: end: #TestHouseholder(f,d,x,x0,eps,N) takes a function f in x #a derivative d, an initial guess x0, a small eps and a #positive integer N an lists the errors between the bisection #method and the Householder method TestHouseholder:=proc(f,d,x,x0,eps,N) local i,L,alpha,x1: alpha:=B(f,x,x0-2,x0+2,eps): if alpha=FAIL then RETURN(FAIL): fi: L:=[]: x1:=x0: for i from 1 to N do x1:=Hd1(f,d,x,x1): L:=[ op(L), abs(x1-alpha[1])]: od: L: end: