Advertisement
cardel

EjemploMDIIGO14Dic

Dec 14th, 2020
1,819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.63 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4. import "math"
  5.  
  6. func recursivo(n int) float64{
  7.  
  8.   if n == 0{
  9.     return 4.0
  10.   }else{
  11.     if n == 1{
  12.       return 8.0
  13.     }else{
  14.       return 7.0*recursivo(n-1)+3.0*recursivo(n-2)
  15.     }
  16.   }
  17. }
  18.  
  19. func formula(n int) float64{
  20.   var A float64 = -6.0/math.Sqrt(61.0)+2.0
  21.   var B float64 = 6.0/math.Sqrt(61.0)+2.0
  22.   var r1 float64 =math.Pow((7.0+math.Sqrt(61.0))/2.0,float64(n))
  23.   var r2 float64 =math.Pow( (7.0-math.Sqrt(61.0))/2.0,float64(n))
  24.  
  25.   return A*r1+B*r2
  26.  
  27. }
  28.  
  29. func main() {
  30.   for i := 0; i<20; i++{
  31.     fmt.Println("n ",i," recursivo ",recursivo(i)," formula ",formula(i))
  32.   }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement