MuPAD Pro Computing Essentials, 2nd Edition

Example 5.6 A recursive procedure

 
recExamp := proc(n: Type::Integer)
begin
   if n<=0 then
      error("Input n>0")
   elif n=1 then
      return(1)
   elif n=2 then
      return(3)
   else
      return(recExamp(n-1)^3 * recExamp(n-2)^2)
   end
end:
 
recExamp(5)
 

4052555153018976267 

 
recExamp(7)

14963083043567875243779945300223588114412915648560338699730878943448806663\
20324917045206101357176493140254308746271763611228639157078727001769235840\
18773768642064902254517051235083715376814046131574445973622027072954767020\
535554713488107

recExamp := proc(n: Type::Integer)
option remember;
begin
   if n<=0 then
      return("Input n>0")
   elif n=1 then
      return(1)
   elif n=2 then
      return(3)
   else
      return(recExamp(n-1)^3 * recExamp(n-2)^2)
   end
end:
  
recExamp(8) // do not use more than 10

14614099865256139595678284064587385712040865015432883966574696465405459510\
21507375170023090516032813661241141066034144877564192299182213451937226156\
57078938060226898062710982853156526120258159967951815896599479347623733480\
31203414436084194453086559921401363103906224411337540859449216595380753937\
83796330075783404024703590619758399994330546314551992745112651787573791852\
64025489338881048511090297264038267184490343524713815021527582255300900784\
14747316638830297420356917366550115940013546342173689125507696757922539297\
82895738698396692391253941413211962187616157596325967733345513927627334615\
97350481883477930495767698827128956052939639937168327454054362702018660893\
66521203660295458716586293298639332838886975098792425431107144052734160706\
51010203828383570176863729124685361907364592985668102502103044854104688707\
8424721196753535561603894427
 

© Miroslaw Majewski, Abu Dhabi,  Update  26-10-2004