isbasov

Ilya Basov

Feb 1st, 2021
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.31 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func main() {
  9.  
  10.     f := poly([]float64{1, 2, 3, 4})
  11.  
  12.     fmt.Println(f(2))
  13. }
  14.  
  15. func poly(a []float64) func(float64) float64 {
  16.  
  17.     return func(x float64) (res float64) {
  18.  
  19.         for i, aa := range a {
  20.             res += aa * math.Pow(x, float64(len(a)-(i+1)))
  21.         }
  22.         return
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment