interpolation

using interp1 in R for matrix

被刻印的时光 ゝ 提交于 2019-12-12 21:43:15
问题 I am trying to use the interp1 function in R for linearly interpolating a matrix without using a for loop. So far I have tried: bthD <- c(0,2,3,4,5) # original depth vector bthA <- c(4000,3500,3200,3000,2800) # original array of area Temp <- c(4.5,4.2,4.2,4,5,5,4.5,4.2,4.2,4) Temp <- matrix(Temp,2) # matrix for temperature measurements # -- interpolating bathymetry data -- depthTemp <- c(0.5,1,2,3,4) layerZ <- seq(depthTemp[1],depthTemp[5],0.1) library(signal) layerA <- interp1(bthD,bthA

Matlab Spline Interpolation Find X from Y

女生的网名这么多〃 提交于 2019-12-12 18:14:43
问题 I need to find the value of x when y = 0. This is my code: x=[2,3,4,5,6]; y=[10,8,4,1,-2]; xi=linspace(2,6,100); yi=interp1(x,y,xi,'spline'); plot(x,y,'o',xi,yi,'-') xlabel('x') ylabel('y') title('Data') I tried using fzero, but I couldn't figure out the proper syntax. I do not have a function f(x) to use, only the points given. 回答1: A couple of things to note: 'spline' refers to cubic spline. Be absolutely certain that is the interpolation technique that you want. Rerun your code with xi

R — Method for Interpolation over 2d datset with missing values

吃可爱长大的小学妹 提交于 2019-12-12 17:21:39
问题 I am currently using the 'Akima' interp routine in order to do 2d linear interpolation. I'm currently trying to do linear interpolations as best as I can by excluding the bad datpoints and interpolated values that depend upon them. I don't want to do any spline fitting just linear interpolation. I can think of two ways to do this using the existing akima package; by partitioning the 2d datasets into valid subsets that do not have missing data points, and then interpolating on each, and then

Interpolate a 3D array in Python

☆樱花仙子☆ 提交于 2019-12-12 17:05:13
问题 I have a 3D NumPy array that looks like this: arr = np.empty((4,4,5)) arr[:] = np.nan arr[0] = 1 arr[3] = 4 arr >>> [[[ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.] [ 1. 1. 1. 1. 1.]] [[ nan nan nan nan nan] [ nan nan nan nan nan] [ nan nan nan nan nan] [ nan nan nan nan nan]] [[ nan nan nan nan nan] [ nan nan nan nan nan] [ nan nan nan nan nan] [ nan nan nan nan nan]] [[ 4. 4. 4. 4. 4.] [ 4. 4. 4. 4. 4.] [ 4. 4. 4. 4. 4.] [ 4. 4. 4. 4. 4.]]] I would like to interpolate along axis=0 so

Why does scipy linear interpolation run faster than nearest neighbor interpolation?

南楼画角 提交于 2019-12-12 10:45:25
问题 I've written a routine that interpolates point data onto a regular grid. However, I find that scipy 's implementation of nearest neighbor interpolation performs almost twice as slow as the radial basis function I'm using for linear interpolation ( scipy.interpolate.Rbf ) Relevant code includes how the interpolators are constructed if interpolation_mode == 'linear': interpolator = scipy.interpolate.Rbf( point_array[:, 0], point_array[:, 1], value_array, function='linear', smooth=.01) elif

Invert interpolation to give the variable associated with a desired interpolation function value

微笑、不失礼 提交于 2019-12-12 10:43:35
问题 I am trying to invert an interpolated function using scipy's interpolate function. Let's say I create an interpolated function, import scipy.interpolate as interpolate interpolatedfunction = interpolated.interp1d(xvariable,data,kind='cubic') Is there some function that can find x when I specify a: interpolatedfunction(x) == a In other words, "I want my interpolated function to equal a; what is the value of xvariable such that my function is equal to a?" I appreciate I can do this with some

Pandas DataFrame: Complex linear interpolation

走远了吗. 提交于 2019-12-12 10:15:32
问题 I have a dataframe with 4 sections Section 1: Product details Section 2: 6 Potential product values based on a range of simulations Section 3: Upper and lower bound for the input parameter to the simulations Section 4: Randomly generated values for the input parameters Section 2 is generated by pricing the product at equal intervals between the upper and lower bound. I need to take the values in Section 4 and figure out the corresponding product value. Here is a possible setup for this

How can I interpolate between 2 points when drawing with canvas?

折月煮酒 提交于 2019-12-12 09:52:12
问题 I have a paint-style application that works with touch events. The JavaScript code is... var RADIUS = 10; var ctx = document.querySelector("canvas").getContext("2d"); var getRandomColorFragment = function () { return Math.floor(Math.random() * 255); }; document.body.addEventListener("touchstart", function (event) { ctx.fillStyle = "rgb(" + [getRandomColorFragment(), getRandomColorFragment(), getRandomColorFragment()].join() + ")"; }); document.body.addEventListener("touchmove", function

interpolation based on one array values

99封情书 提交于 2019-12-12 06:38:13
问题 I have two arrays with values: x = np.array([100, 123, 123, 118, 123]) y = np.array([12, 1, 14, 13]) I want to evaluate for example the function: def func(a, b): return a*0.8 * (b/2) So, I want to fill the y missing values. I am using: import numpy as np from scipy import interpolate def func(a, b): return a*0.8 * (b/2) x = np.array([100, 123, 123, 118, 123]) y = np.array([12, 1, 14, 13]) X, Y = np.meshgrid(x, y) Z = func(X, Y) f = interpolate.interp2d(x, y, Z, kind='cubic') Now, I am not

Polyfit and polyval to perform interpolation

怎甘沉沦 提交于 2019-12-12 05:49:52
问题 I have x = linspace(-5,5,256) y = 1./(1+x.^2) plot(x,y,'...') %plot of (x,y) I want to estimate this with a polynomial of order 10, such that the polynomial intersects the graph at 11 points. So, I did this: x2 = linspace(-5,5,11) y2 = 1./(1+x2.^2) p = polyfit(x2,y2,10) %finds coefficients of polynomial of degree 10 that fits x2,y2 y3 = polyval(p,x2) plot(x,y,x2,y3,'...') I thought the polyfit would give me the coefficients for a polynomial up to order 10, which intersects the points (x2,y2)