Deven Singh, Assignment 5, 09/20/2021 #OK To Post Homework #Question 0 eq := {6*a(n - 1) + a(n + 3) + 5*a(n + 1) = 0}; subs(n = n - 3, eq); # a(n) = 0*a(n-1)-5*a(n-2)+0*a(n-3)-6*a(n-4) RecToSeq := proc(INI, REC, N) local i, k, L, newguy; if not (type(INI, list) and type(REC, list) and nops(INI) = nops(REC) and type(N, integer) and nops(INI) <= N) then print(`bad innput`); RETURN(FAIL); end if; k := nops(INI); L := INI; while nops(L) < N do newguy := add(REC[i]*L[-i], i = 1 .. k); L := [op(L), newguy]; end do; L; end proc; A := RecToSeq([1, 2, 4, 11], [0, -5, 0, -6], 1000); A[1000]: evalf(%); 1.82*10^239 #Question 1 GrowthC := proc(INI, REC, K) local L, a, b; L := RecToSeq(INI, REC, K); a := L[-1]/L[-2]; b := L[-2]/L[-3]; if abs(a - b) < 1/10^(Digits + 3) then RETURN(evalf(a)); else print(` make `, K, `bigger `); RETURN(FAIL); end if; end proc; GrowthC([0, 1, 1, 2, 4, 8, 16, 32, 64, 128], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 1000); 1.999 GrowthCe := proc(REC) local x, i; evalf([solve(1 - add(REC[i]/x^i, i = 1 .. nops(REC)))])[1]; end proc; GrowthCe([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); 1.999 #Question 2 #Part i LeslieMod := proc(SUR, FER) local i, L, A; if not (type(SUR, list) and type(FER, list) and nops(SUR) + 1 = nops(FER)) then print(`bad input`); RETURN(FAIL); end if; A := nops(SUR); L[0] := 1; for i to A do L[i] := L[i - 1]*SUR[i]; end do; [seq(FER[i + 1]*L[i], i = 0 .. A)]; end proc; LeslieMod([0.99, 0.99], [0, 1/2, 1/4]): GrowthCe(%); .88 #Part ii LeslieMat := proc(SUR, FER) local i, A; if not (type(SUR, list) and type(FER, list) and nops(SUR) + 1 = nops(FER)) then print(`bad input`); RETURN(FAIL); end if; A := nops(SUR); matrix([FER, seq([0 $ (i - 1), SUR[i], 0 $ (A + 1 - i)], i = 1 .. A)]); end proc; with(LinearAlgebra): LeslieMat([0.99, 0.99], [0, 1/2, 1/4]): E := Matrix([[0, 1/2, 1/4], [0.99, 0, 0], [0, 0.99, 0]]); evalf(Eigenvalues(E)); #The largest eigenvalue is .88 #Question 3 GrowthCe([0, 0, 0, 0.16, 0.41]); .89 #Question 4 PlantGseq := proc(alpha, beta, gamma, sigma, INI, K) local a, b; if `not`(type(INI, list) and nops(INI) = 2 and type(K, integer) and nops(INI) <= K) then print(`bad input`); RETURN(FAIL); end if; a := alpha*sigma*gamma; b := beta*sigma^2*(1 - alpha)*gamma; RecToSeq(INI, [a, b], K); end proc; PlantGseq(0.5, 0.25, 2.0, 0.8, [100, 80], 20); PlantGseq(0.6, 0.3, 2.0, 0.8, [100, 96], 20); #Both outputs match pg.18 Table 1.1 #Question 5 PlantGseq2 := proc(alpha, beta, gamma, sigma) local a, b; if `not`(type(alpha, float) and type(beta, float) and type(gamma, float) and type(sigma, float)) then print(`bad input`); RETURN(FAIL); end if; a := alpha*sigma*gamma; b := beta*sigma^2*(1 - alpha)*gamma; GrowthCe([a, b]); end proc; PlantGseq2(0.5, 0.25, 2.0, 0.8); .97 PlantGseq2(0.6, 0.3, 2.0, 0.8); 1.1