# question about plotting points and calculating the average slope

I have a list points to plot like:

X = [3.2467532467532467, 3.236245954692557, 3.215434083601286, 3.1746031746031744, 3.125, 3.0864197530864197, 3.048780487804878, 3.003003003003003, 2.9239766081871346, 2.840909090909091, 2.8011204481792715, 2.7624309392265194, 2.73224043715847, 2.680965147453083, 2.6525198938992043]

Y = [1.449645784571558, 1.4733737963401687, 1.4065612375015262, 1.7345137207779688, 1.8754959195583569, 2.1035354414847736, 2.1388130187811201, 2.3224700713378144, 2.6092616151384149, 2.9660818973522378, 3.1351199784336701, 3.2953129727168911, 3.4245247041968971, 3.5986044560957482, 3.7007780808250552]

how can I plot X and Y? plot(Y, X) returns ValueError: too many values to unpack

And I must also find the average slope. how to find that?

edit retag close merge delete

Sort by ยป oldest newest most voted

As for the plotting part, there is a points command that will do what you want. You'll want to zip up the points first, given its syntax.

Pts = zip(X,Y) # this should make a list of pairs from X and Y
points(Pts,size=10,color='red') # the command, with a couple standard options


I'm not sure if your other question is well-defined. Have you tried doing a linear regression? There are several ways to do this in Sage, though most of them require using one of its subpackages...

more

Seeing the nobody has given a smart answer to this question so far, here is just my stupid yet quick hand-made solution:

plot_list=[]
i=0
plot_list.append((X[i],Y[i]))
slope = 0
for i in range(1,len(X)):
plot_list.append((X[i],Y[i]))
slope += (Y[i]-Y[i-1])/(X[i]-X[i-1])

slope /= len(X)
print("Average slope = {0}".format(slope))

list_plot(plot_list)

more