Ask Your Question
0

question about plotting points and calculating the average slope

asked 2011-08-21 20:58:20 -0500

ebs gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2011-08-22 02:10:27 -0500

kcrisman gravatar image

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...

edit flag offensive delete link more
0

answered 2011-08-21 23:47:57 -0500

v_2e gravatar image

updated 2011-08-21 23:49:39 -0500

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-08-21 20:58:20 -0500

Seen: 1,152 times

Last updated: Aug 22 '11