curve-fitting

Finding the intersection of a curve from polyfit

ぃ、小莉子 提交于 2019-12-05 12:52:38
This seems simple but I can't quite figure it out. I have a curve calculated from x,y data. Then I have a line. I want to find the x, y values for where the two intersect. Here is what I've got so far. It's super confusing and doesn't give the correct result. I can look at the graph and find the intersection x value and calculate the correct y value. I'd like to remove this human step. import numpy as np import matplotlib.pyplot as plt from pylab import * from scipy import linalg import sys import scipy.interpolate as interpolate import scipy.optimize as optimize w = np.array([0.0, 11

SciPy leastsq fit to a sine wave failing

雨燕双飞 提交于 2019-12-05 10:56:05
I am trying to figure out what it is I don't understand here. I am following http://www.scipy.org/Cookbook/FittingData and trying to fit a sine wave. The real problem is satellite magnetometer data which makes a nice sine wave on a spinning spacecraft. I created a dataset then am trying to fit it to recover the inputs. Here is my code: import numpy as np from scipy import optimize from scipy.optimize import curve_fit, leastsq import matplotlib.pyplot as plt class Parameter: def __init__(self, value): self.value = value def set(self, value): self.value = value def __call__(self): return self

Fitting exponential function through two data points with scipy curve_fit

自古美人都是妖i 提交于 2019-12-05 09:45:33
I want to fit an exponential function y=x ** pw with a constant pw to fit through two datapoints. The scipy curve_fit function should optimise adj1 and adj2 . I have tried with the code below but couldn't get it to work. The curve does not go through the datapoints. How can I fix it? import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit def func(x, adj1,adj2): return np.round(((x+adj1) ** pw) * adj2, 2) x = [0.5,0.85] # two given datapoints to which the exponential function with power pw should fit y = [0.02,4] pw=15 popt, pcov = curve_fit(func, x, y) xf=np

How to fit a curve to a damped sine wave in matlab

假如想象 提交于 2019-12-05 07:46:33
问题 I have some measurements done and It should be a damped sine wave but I can't find any information on how to make (if possible) a good damped sine wave with Matlab's curve fitting tool. Here's what I get using a "Smoothing spline": Image http://s21.postimg.org/yznumla1h/damped.png. Edit 1 : Here's what I got using the "custom equation" option: Edit 2 : I've uploaded the data to pastebin in csv format where the first column is the amplitude and the second is the time. 回答1: The damped sin

Simultaneous data fitting in python with leastsq

流过昼夜 提交于 2019-12-05 07:21:42
问题 I didn't program for a long time and never was good at it, but it is kind of important task I am struggling with. I am trying to fit two sets of data (x – time, y1 and y2 – different columns of values which should be read from text file). For each dataset (y1 and y2) I have a function which should fit them. Inside both of the functions I have several parameters to be fitted. For some time values the data for "y" is absent, so the task is to program it somehow when “y” is missing and fit the

Matlab curve fitting tool, cftool, generate code function does not give the same fit

耗尽温柔 提交于 2019-12-05 06:29:15
问题 I am using Matlab's curve fitting tool, cftool , to fit a set of points which I have. The problem I am facing is that the generate code function will not give me the same fit as produced in the cftool . This is not what I want because I want to be able to retrieve the data from the residual plot. I could also just copy the function from cftool and do it manually. But I do not understand why the generated code will not just give me the same curve fit. The cftool session file: http://dl.dropbox

geom_smooth and exponential fits

此生再无相见时 提交于 2019-12-05 06:09:04
I am new to R and I'm having some difficulty plotting an exponential curve using ggplot2. I have a set of data below. DATA X Y x y 1 0.6168111 37.20637 0.6168111 37.20637 2 0.5478698 24.17084 0.5478698 24.17084 3 0.6082697 26.21261 0.6082697 26.21261 4 0.6094899 26.14065 0.6094899 26.14065 5 0.6095040 38.56314 0.6095040 38.56314 6 0.6933108 36.78443 0.6933108 36.78443 7 0.5796637 27.82840 0.5796637 27.82840 8 0.4716866 30.63080 0.4716866 30.63080 9 0.5291792 29.78255 0.5291792 29.78255 10 1.2520000 33.12657 1.2520000 33.12657 11 1.2260000 31.81066 1.2260000 31.81066 12 1.2690000 59.91388 1

Scatter plot kernel smoothing: ksmooth() does not smooth my data at all

风流意气都作罢 提交于 2019-12-05 05:59:37
Original question I want to smooth my explanatory variable, something like Speed data of a vehicle, and then use this smoothed values. I searched a lot, and find nothing that directly is my answer. I know how to calculate the kernel density estimation ( density() or KernSmooth::bkde() ) but I don't know then how to calculate the smoothed values of speed. Re-edited question Thanks to @ZheyuanLi, I am able to better explain what I have and what I want to do. So I have re-edited my question as below. I have some speed measurement of a vehicle during a time, stored as a data frame vehicle : t

Add constraints to scipy.optimize.curve_fit?

六眼飞鱼酱① 提交于 2019-12-05 05:59:24
I have the option to add bounds to sio.curve_fit. Is there a way to expand upon this bounds feature that involves a function of the parameters? In other words, say I have an arbitrary function with two or more unknown constants. And then let's also say that I know the sum of all of these constants is less than 10. Is there a way I can implement this last constraint? import numpy as np import scipy.optimize as sio def f(x, a, b, c): return a*x**2 + b*x + c x = np.linspace(0, 100, 101) y = 2*x**2 + 3*x + 4 popt, pcov = sio.curve_fit(f, x, y, \ bounds = [(0, 0, 0), (10 - b - c, 10 - a - c, 10 - a

Sinusoidal fitting classes for c#

我只是一个虾纸丫 提交于 2019-12-05 05:54:42
I am wondering if there is a class for fitting data to a sine curve. I found an algorithm for it here but it would take some time to first understand and then code... Before I go down that road I am wondering if the forum knows of a class that is already created for such mathematical modeling. CharlesB C# does not have a long tradition of scientific computing libraries... My take would be to get one of the numerous numerical computation routine packages (like on of them , or the Numerical Recipes) in C/C++, and wrap it under C#. See also this Math.SE post . On the commercial side, NMath