1

suppose I have

t= [0,7,10,17,23,29,31]

f_t= [4,3,11,19,12,9,17]

and I have plotted f_t vs t.

Now from plotting these 7 data points, I want to retrieve 100 data points and save them in a text file. What do I have to do?

Note that I am not asking about the fitting of the plot; I know between two points the plot is linear.

What I am asking If I create a array like t=np.arange(0,31,.1), then what is the corresponding array of f_t which agrees well with the previous plot, i.e., for any t between t=0 to t=7, f_t will be determined by using a straight line connecting (0,4) and (7,3), and so on.

2 Answers 2

2

You should use a linear regression, that gives you a straight line formula, in which you can grasp as many points as you want.

If the line is more of a curve, then you should try to have a polynomial regression of higher degree.

ie:

import pylab
import numpy

py_x =  [0,7,10,17,23,29,31]

py_y = [4,3,11,19,12,9,17] 

x = numpy.asarray(py_x)
y = numpy.asarray(py_y)

poly = numpy.polyfit(x,y,1) # 1 is the degree here. If you want curves, put 2, 3 or 5...

poly is now the polynome you can use to calculate other points with.

for z in range(100):
    print numpy.polyval(poly,z) #this returns the interpolated f(z)
Sign up to request clarification or add additional context in comments.

1 Comment

I don't want a fitting. I just want values of f_t at different times from the plot of t= [0,7,10,17,23,29,31] f_t= [4,3,11,19,12,9,17]
1

The function np.interp will do linear interpolation between your data points:

f2 = np.interp(np.arange(0,31,.1), t, ft)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.