# Load the data. It expects data in rows, where each set of data is comma separated.
# The time should be in the first column, and position in the second.
# It ignores any other columns, although you could have yours read in velocity or whatever.
#
#It must have data in the first row. Remove any headers or column names.

# Now go row by row through the file, and add the data from the first column (number 0) to time array
# and the second column (number 1) to position array
#for row in f.text.splitlines():
#cols = row.split(",")
# t_data.append(float(cols[0]))
# x_data.append(float(cols[1]))

# put it on the graph, too. X = time, Y = position
# expt.plot(float(cols[0]), float(cols[1]))

####
## Now simulate those results. Below here is what you'll need to change for your experiment
####

#Set some CONSTANTS
g = -9.8
deltat = .05 #the time interval for each loop in seconds; choose any small value
mass = 0.022 # This was measured
Pi=3.14
#My oscillator was a mass on a horizontal spring. Your oscillator may depend on different factors

D = 1000 # This was measured. You could also use it as a fitting parameter that you vary (kg)

p = D #Rho
f_friction = 1.1 # This is probably hard to measure, so I'll use it as a fitting parameter to vary
# starting with 0 is a good way to see that the oscillation in your simulaiton works
y_init = -0.028 # look at your first data point
y_equil = -0.017 # the point around which you oscillate. A good choice to start with comes from the data
r=0.015
#SET INITIAL VALUES OF THINGS
t = 0 #initialize time. Choose the first time point of your experimental data so the graphs can match
v_i = vec(0,1,0) #initialize speed. Look at your first position data points to estimate the initial speed

#DEFINE SOME OBJECTS
#First, my block
container = cylinder(pos=vec(0,y_init,0), size = vector(.03, .049, .03), v = v_i)
#I could add the spring, but it would only be for show

#THE CALCULATION - THIS LOOP IS WHERE ALL THE MAGIC HAPPENS
while t < 6.8: #tell it how long to run the loop, in seconds (how long does your experimental data go?)
rate(40) #tell it how quickly to run the loop (bigger numbers are faster)
H= container.pos
V= Pi*r^2*H
v=v_i

Well, it's not C++. Matlab at a guess.
Edit your question, and correct the tags to match whatever the heck that is, and then tell us where and when the error occurs - just dumping code on us and saying "it don't work" tells us nothing much at all.

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

Use the "Improve question" widget to edit your question and provide better information.

1 solution

Solution 1

v_i = vec(0,1,0) #initialize speed. Look at your first position data points to estimate the initial speed
...
v=v_i # so v is defined as a vector
...
v = v + a*deltat # you cannot add a single value to a vector