Created
November 7, 2016 12:00
-
-
Save angellicadearaujo/c9030224a571acdb20d82006a617b8e0 to your computer and use it in GitHub Desktop.
Mínimos quadrados para equações lineares
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def MinimoQuadrado(h,e): | |
| n=len(h) | |
| sh=0 | |
| se=0 | |
| shh=0 | |
| she=0 | |
| m=0 | |
| b=0 | |
| # Prepare the sum for the equatio y = x*m + b | |
| for i in range(n): | |
| sh += h[i] | |
| se += e[i] | |
| shh += h[i]*h[i] | |
| she += h[i]*e[i] | |
| m= (n-1)*she - sh*se | |
| m= m*((1/float((n-1))*shh - sh*sh)) | |
| b= ((se) - (m*sh))*(1/float(n-1)) | |
| # Build y | |
| y=[] | |
| for i in range(n): | |
| y.append((h[i]*m + b)) | |
| return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment