interpolation

Matlab: Find a root of y-values given by a differential equation

こ雲淡風輕ζ 提交于 2019-11-28 14:08:15
I've solved an initial value differential equation and plotted the Y values given by ODE45. From the plot I can vaguely tell where the root should be, but in the given task I need to find it with great accuracy. My first guess was to adjust a polynom to my X and Y values, and then solve the polynom equation. But I used polyfit and had 69 know values which gave me a polynom of the 68grade which I couldn't solve. So, does anyone know how I could find a "root" to a set of given Y values without knowing the actual equation? It's written in the task that interpolation should be used! Thanks in

Error in calculating integral for 2D interpolation. Comparing numpy arrays

狂风中的少年 提交于 2019-11-28 13:02:25
My optimization task deals with calculation of the following integral and finding the best values of xl and xu : Iterations take too long, so I decided to speed them up by calculating integral for all possible values xl and xu and then interpolate calculated values during optimization. I wrote the following function: def k_integrand(x, xl, xu): return((x**2)*mpmath.exp(x))/((xu - xl)*(mpmath.exp(x)-1)**2) @np.vectorize def K(xl, xu): y, err = integrate.quad(k_integrand, xl, xu, args = (xl, xu)) return y and two identical arrays grid_xl and grid_xu with dinamic increment of values. When I run

Cubic spline interpolation vs polynomial interpolation

瘦欲@ 提交于 2019-11-28 13:01:21
I am asked to investigate the different types of interpolation using Matlab for the following points: x = [32 34 35 36 37 38] y = [26 28 31 30 29 25] and find the values for f(33) , f(33.5) and f(35) . When plotting x and y, I can see that f(33) should be around 27, which is also what I get using interp1(x,y,33) . I am not sure if this is the correct way of using the Cubic spline interpolation function but I used spline(x,y,33) and got ans = 24.3906 . Shouldn't I still get the same value for f(33) no matter what type of interpolation I use? Interpolation makes sure the values of the

Is there an R library that estimates a multivariate natural cubic spline (or similar) function?

て烟熏妆下的殇ゞ 提交于 2019-11-28 11:41:18
note: originally posted on Cross Validated (stats SE) on 07-26-2011, with no correct answers to date. Background I have a model, f , where Y=f( X ) X is an n x m matrix of samples from m parameters and Y is the n x 1 vector of model outputs. f is computationally intensive, so I would like to approximate f using a multivariate cubic spline through ( X ,Y) points, so that I can evaluate Y at a larger number of points. Question Is there an R function that will calculate an arbitrary relationship between X and Y ? Specifically, I am looking for a multivariate version of the splinefun function,

MATLAB: Using interpolation to replace missing values (NaN)

隐身守侯 提交于 2019-11-28 11:19:22
I have cell array each containing a sequence of values as a row vector. The sequences contain some missing values represented by NaN . I would like to replace all NaNs using some sort of interpolation method, how can I can do this in MATLAB? I am also open to other suggestions on how to deal with these missing values. Consider this sample data to illustrate the problem: seq = {randn(1,10); randn(1,7); randn(1,8)}; for i=1:numel(seq) %# simulate some missing values ind = rand( size(seq{i}) ) < 0.2; seq{i}(ind) = nan; end The resulting sequences: seq{1} ans = -0.50782 -0.32058 NaN -3.0292 -0

How to use linear interpolation estimate current position between two Geo Coordinates?

冷暖自知 提交于 2019-11-28 11:19:04
I have the following available: last reported lat,lon w/timestamp target lat,lon estimated time to target heading How can I interpolate an estimated position over time? I know that's enough to calculate the required average velocity for the remainder of the trip. Given a straight-line distance, it's pretty trivial. I know it has to do with vectors but I'm a bit rusty and thought it better to consult some experts. The reason I need this update rate is limited, so to show smooth animation I need to guess at the current position between updates. The target platform is a Google Maps application so

Interpolation over an array (or two)

爷,独闯天下 提交于 2019-11-28 11:18:26
I'm looking for a java library or some help to write my own interpolation function. That is I have two arrays of doubles which are potentially different sizes, but are ordered. I need to be able to make an estimate of intermediate values, and insert so that both arrays become the same size. In fact the total number of points appearing in the interpolation is the sum of the 2 array sizes minus 1. The range of each array must stay the same however, so there is no extrapolation needed. eg. a1 = [1, 4, 9, 16, 25, 36] and a2 = [6, 9, 14, 30] the results could be eg. a1 = [1, 2.25, 4, 6.25, 9, 12.25

Interpolating a closed curve using scipy

会有一股神秘感。 提交于 2019-11-28 11:15:59
I'm writing a python script to interpolate a given set of points with splines. The points are defined by their [x, y] coordinates. I tried to use this code: x = np.array([23, 24, 24, 25, 25]) y = np.array([13, 12, 13, 12, 13]) tck, u = scipy.interpolate.splprep([x,y], s=0) unew = np.arange(0, 1.00, 0.005) out = scipy.interpolate.splev(unew, tck) which gives me a curve like this: However, I need to have a smooth closed curve - on the picture above the derivatives at one of the points are obviously not the same. How can I achieve this? ali_m Your closed path can be considered as a parametric

Interpolation between two images with different pixelsize

别来无恙 提交于 2019-11-28 11:08:43
问题 For my application, I want to interpolate between two images(CT to PET). Therefore I map between them like that: [X,Y,Z] = ndgrid(linspace(1,size(imagedata_ct,1),size_pet(1)),... linspace(1,size(imagedata_ct,2),size_pet(2)),... linspace(1,size(imagedata_ct,3),size_pet(3))); new_imageData_CT=interp3(imagedata_ct,X,Y,Z,'nearest',-1024); The size of my new image new_imageData_CT is similar to PET image. The problem is that data of my new image is not correct scaled. So it is compressed. I think

Spline Interpolation with Python

半城伤御伤魂 提交于 2019-11-28 11:04:39
I wrote the following code to perform a spline interpolation: import numpy as np import scipy as sp x1 = [1., 0.88, 0.67, 0.50, 0.35, 0.27, 0.18, 0.11, 0.08, 0.04, 0.04, 0.02] y1 = [0., 13.99, 27.99, 41.98, 55.98, 69.97, 83.97, 97.97, 111.96, 125.96, 139.95, 153.95] x = np.array(x1) y = np.array(y1) new_length = 25 new_x = np.linspace(x.min(), x.max(), new_length) new_y = sp.interpolate.interp1d(x, y, kind='cubic')(new_x) but I am getting: ValueError: A value in x_new is below the interpolation range. in interpolate.py Any help would be appreciated. From the scipy documentation on scipy