python - Piecewise function: Find equation and solve it using data points -


I have several points because sometimes 1 or 2 can be unknown (both x and y coordinate), i And find those wrong marks, if possible by numpy. Simplified Model:

  a = np.arange (12) x = np.array ([1000,1010,1020,1030,1040,1050,1060,1070,1080,109, 1100, 1110]) y = NP. Array ([0,50,100,250,300,350,500,550,600,750,800,850])   

Which looks like:

  [[1 2 3 4 5 6 7 8 9 10 11] [1000 1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110] [0 50 100 250 300 350 500 550 600 750 800 850]]   

As you can see, 10 to 10 in X Increase, increase of y 50, then 50, then 150, and so on. I tried to solve the problem with at least sections, but it is not satisfactory:

  A = NP Array ([x, np.ones (12))) m, c = np.linalg.lstsq (at, y) [0] sol = m * x + c print sol. This return:  [- 23 58 13 9 221 302 384 465 547 628 710 791 873] Question: To get the results of the data point For, to move forward, preferably to use lower? Thanks Dominic   

On what basis are you saying that the results are not close to the data points when I I plot, so they look good to me:

  #! / Usr / bin / env python2.7 import matplotlib.pyplot as plt import numpy np to scipy.interpolate import interp1d x = np.array ([1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080 , 10 9, 1100, 1110]) y = np. Array ([0, 50, 100, 250, 300, 350, 500, 550, 600, 750, 800, 850]) A = NP. Vstack ([x, np.ones (12)]) m, c = np.linalg.lstsq (at, y) [0] sol = m (x, y, 'o', label = 'data') plat. Plt.plot (x, finterp (x), '-', label = 'interpolated') plt.xlabel ('x') plt.ylabel (plot x) 'Y') plt.legend (loc = 'best' ) plt.show ()   

Based on the comments, I added the interpolation I really do not like this approach (I like to define the function, if it is already Is known only) as if the data is noise, you may end up in the end, but it seems like what the interpolation wants. img src = "https://i.stack.imgur.com/6PCI4.png" alt = "Enter image details here">

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -