Plotting Graph Functions using Gnuplot

A

arslanburney

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[0] + sigmax
sigmay = uinput[1] + sigmay
sigmaxy = uinput[0] * uinput [1] + sigmaxy
sigmaxwhl = sigmax * sigmax
sigmaxsq = uinput[0] * uinput[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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top