By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,538 Members | 1,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,538 IT Pros & Developers. It's quick & easy.

Plotting Graph Functions using Gnuplot

P: n/a
Hello. Needed some help again. Im trying to calculate the best fit
line here. Given a set of points in a list. However, wirte in the end
where i plot the line it tells me tht the variable is not defined.
Either try correcting this or tell me a subsitute that i could use.
Thnks. Heres the code:
#File name Bestfit.py

import Gnuplot

def bestfit(uinput):

if not isinstance(uinput, list):
return False

else:
sigmax = sigmay = sigmaxy = sigmaxwhl = sigmaxsq = 0

for i in range(len(uinput)):

n = len(uinput)

sigmax = uinput[i][0] + sigmax
sigmay = uinput[i][1] + sigmay
sigmaxy = uinput[i][0] * uinput [i][1] + sigmaxy
sigmaxwhl = sigmax * sigmax
sigmaxsq = uinput[i][0] * uinput[i][0] + sigmaxsq
sigmaxsigmay = sigmax * sigmay

num = sigmaxsigmay - (n * sigmaxy)
den = sigmaxwhl - (n* sigmaxsq)

num2 = (sigmax * sigmaxy) - (sigmay * sigmaxsq)
gradient = num / den

intercept = num2 / den

m = gradient
c = intercept
y = m*x + c
plot (y)
-------

import Bestfit

Bestfit.bestfit([(2,3), (3,8), (5,7), (4,9)])
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
No help yet?
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.