0
from scitools.std import *
t = []
v = []
infile = open('running.txt', 'r')
for line in infile:
    tnext, vnext = line.strip().split(',')
    t.append(float(tnext))
    v.append(float(vnext))
infile.close()

a = []
for i in range(len(t)-1):
    a.append((v[i+1] - v[i])/(t[i+1] - t[i]))

s = []

for i in range(len(t)-1):
    s.append((v[i+1])*(t[i+1]-t[i]))

plot(t, a)
plot(t, s)

This is the outcome of the code(error):

Traceback (most recent call last):

  File "******1c.py", line 20, in <module>
    plot(t, a)

  File "/usr/lib/python2.6/site-packages/scitools/easyviz/common.py", line 3046, in plot
    format=''))

  File "/usr/lib/python2.6/site-packages/scitools/easyviz/common.py", line 372, in __init__
    self.setp(**kwargs)

  File "/usr/lib/python2.6/site-packages/scitools/easyviz/common.py", line 445, in setp
    'not %d.' % (size(x),size(x),size(y))

AssertionError: Line.setp: x has size 1219, expected y to have size 1219, not 1218.

The problem is on the last line. I have 1219 x points and 1218 y points. How can I fix this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    What do you intend the result to be? Your loop relies on "looking ahead" one value to `t[i+1]`, so you can't have as many values in `a` as in `t`. You could do `plot(t[:-1], a)` to leave out the last element of `t`. – BrenBarn Nov 05 '14 at 19:13
  • @BrenBarn Thanks for your help. I changed the "looking ahead" loop to "presence". Again Thanks! :) – The Maths ProorBro Nov 05 '14 at 19:53

0 Answers0