# C21.txt, Apr. 5, 2018, Experimental Mathematics (Rutgers), Spring 2018 #as taken by Edna Jones Help:=proc() print(`EvalCFg(A,B), Tanh(n,x), FWB(n,x,p), MyPade(f,x,m,n), PadeExp(f,x,m,n), FWBg(n,x,y,p) `): end: # EvalCFg(A, B): evaluates a general continued fraction with numerators B and denominators A EvalCFg := proc(A,B) if not (type(A,list) and nops(A)>0) then return FAIL; fi: if not (type(B,list) and nops(B)>0) then return FAIL; fi: if nops(A) <> nops(B) then return FAIL; fi: if nops(A)=1 then return B[1]/A[1]; fi: return B[1]/(A[1] + EvalCFg([op(2..nops(A), A)], [op(2..nops(B), B)])); end: # Tanh(n,x): the truncated continued fraction from Chrystal for tanh(x) Tanh := proc(n,x) local j: EvalCFg([seq(2*j-1, j=1..n)],[x, (x^2)$(n-1)]); end: # FWB(n,x,p): the truncated continued fraction replacing 2*j-1 in tanh(x) by a general function so Tanh(n,x) is FWB(n,x,k->2*k-1). FWB := proc(n,x,p) local j: EvalCFg([seq(p(j), j=1..n)],[x, (x^2)$(n-1)]); end: # MyPade(f,x,m,n): inputs a function f of the variable x and nonnegative integers m and n outputs a rational function of x with numerator of at most m and denominator of at most n such that the firs m+n-1 Taylor coefficients of f-MyPade(f,x,m,n) are zero MyPade := proc(f,x,m,n) local T, B, j, t, b, eq, var, guess, solnVar: # f-T/B to be small B*f-T should have the first m+n-1 coefficients equal to 0 T := add(t[j]*x^j, j=0..m); B := 1 + add(b[j]*x^j, j=1..n); var := {seq(t[j], j=0..m), seq(b[j], j=1..n)}; guess := taylor(B*f-T, x=0, m+n+1); eq := {seq(coeff(guess,x,j),j=0..m+n)}; solnVar := solve(eq,var); if solnVar = NULL then return FAIL; fi: subs(solnVar,T)/subs(solnVar,B); end: # PadeExp(f,x,m,n): inputs a function f of the variable x and nonnegative integers m and n outputs a rational function of exp(x) with numerator of at most m and denominator of at most n such that the firs m+n-1 Taylor coefficients of f-MyPade(f,x,m,n) are zero PadeExp := proc(f,x,m,n) local T, B, j, t, b, eq, var, guess, solnVar: # f-T/B to be small B*f-T should have the first m+n-1 coefficients equal to 0 T := add(t[j]*exp(x*j), j=0..m); B := 1 + add(b[j]*exp(x*j), j=1..n); var := {seq(t[j], j=0..m), seq(b[j], j=1..n)}; guess := taylor(B*f-T, x=0, m+n+1); eq := {seq(coeff(guess,x,j),j=0..m+n)}; solnVar := solve(eq,var); if solnVar = NULL then return FAIL; fi: subs(solnVar,T)/subs(solnVar,B); end: #added after class # FWBg(n,x,y,p): the truncated continued fraction replacing 2*j-1 in tanh(x) by a general function so Tanh(n,x) is FWB(n,x,k->2*k-1). FWBg := proc(n,x,y,p) local j: EvalCFg([seq(p(j), j=1..n)],[x, y$(n-1)]); end: