Advertisement
Guest User

ex1

a guest
Mar 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  MC886.py
  5. #  
  6. #  Copyright 2017 Andre Muricy <ra134949@lazaro.lab.ic.unicamp.br>
  7. #  
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #  
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #  
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. #  MA 02110-1301, USA.
  22. #  
  23. #  
  24. import sklearn
  25.  
  26. x = [-5.0,  -4.0,   -3.0,   -2.0, -1.0,   0.0,  1.0,  2.0,  3.0,  4.0,  5.0]
  27. y = [-53.9, -28.5,  -20.7,  -3.6, -9.8,   5.0,  4.2,  5.1,  11.4, 27.4, 44.0]
  28.  
  29. def fun(a, b, c, d, xi):
  30.   res = a*xi*xi*xi + b*xi*xi + c*xi + d
  31.   return res
  32.  
  33. def gun(a, b, c, d):
  34.   acc = 0
  35.   for i in range(0, len(x)):
  36.     acc = acc + ( y[i] - fun(a, b, c, d, x[i]) ) * ( y[i] - fun(a, b, c, d, x[i]) )
  37.   return acc
  38.  
  39.  
  40. print (gun(0, 0, 0, 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement