derivative

Function for polynomials of arbitrary order (symbolic method preferred)

≯℡__Kan透↙ 提交于 2019-11-28 12:26:00
I've found polynomial coefficients from my data: R <- c(0.256,0.512,0.768,1.024,1.28,1.437,1.594,1.72,1.846,1.972,2.098,2.4029) Ic <- c(1.78,1.71,1.57,1.44,1.25,1.02,0.87,0.68,0.54,0.38,0.26,0.17) NN <- 3 ft <- lm(Ic ~ poly(R, NN, raw = TRUE)) pc <- coef(ft) So I can create a polynomial function: f1 <- function(x) pc[1] + pc[2] * x + pc[3] * x ^ 2 + pc[4] * x ^ 3 And for example, take a derivative: g1 <- Deriv(f1) How to create a universal function so that it doesn't have to be rewritten for every new polynomial degree NN ? My original answer may not be what you really want, as it was

Find all local Maxima and Minima when x and y values are given as numpy arrays

送分小仙女□ 提交于 2019-11-28 00:03:53
I have two arrays x and y as : x = np.array([6, 3, 5, 2, 1, 4, 9, 7, 8]) y = np.array([2, 1, 3, 5, 3, 9, 8, 10, 7]) I am finding index of local minima and maxima as follows: sortId = np.argsort(x) x = x[sortId] y = y[sortId] minm = np.array([]) maxm = np.array([]) while i < y.size-1: while(y[i+1] >= y[i]): i = i + 1 maxm = np.insert(maxm, 0, i) i++ while(y[i+1] <= y[i]): i = i + 1 minm = np.insert(minm, 0, i) i++ What is the problem in this code? The answer should be index of minima = [2, 5, 7] and that of maxima = [1, 3, 6] . You do not need this while loop at all. The code below will give

Compute a derivative using discrete methods

倖福魔咒の 提交于 2019-11-27 20:49:37
I am looking for a method to compute a derivative using a discrete and fast method. Since now I do not know the type of equation I have, I am looking for discrete methods analog to the ones that we can find for the integral such as, the Euler method. Andrea Ambu I think you are looking for the derivative calculated in a point. If this is the case, here there is a simple way to do that. You need to know the derivative in a point, say a . It is given by the limit of the difference quotient for h->0: You actually need to implement the limit function. So you: Define an epsilon, set it more small

Matlab gradient equivalent in opencv

此生再无相见时 提交于 2019-11-27 19:26:37
问题 I am trying to migrate some code from Matlab to Opencv and need an exact replica of the gradient function. I have tried the cv::Sobel function but for some reason the values in the resulting cv::Mat are not the same as the values in the Matlab version. I need the X and Y gradient in separate matrices for further calculations. Any workaround that could achieve this would be great 回答1: Sobel can only compute the second derivative of the image pixel which is not what we want. (f(i+1,j) + f(i-1,j

Calculate the derivative of a vector

浪子不回头ぞ 提交于 2019-11-27 09:38:26
I have the following function (Viviani's curve): Phi = @(t)[ cos(t)^2, cos(t)*sin(t), sin(t) ] Just a check that it's valid: s = linspace(0,T,1000); plot3(cos(s).^2, cos(s).*sin(s), sin(s)); How to derivate the function Phi (maybe multiple times), which represents Viviani's curve in a point t where t goes from 0 to 2*pi ? Did I defined Phi suitable for such a derivative? I've tried diff , but it did not keep the Phi as I would need it. If the second derivative would be Phi_d2 , I need to get it's value (for example in t = 0 ). How can I achieve this? Here are three ways you can accomplish this

In pyomo how can one extract the second derivative from the objective function

独自空忆成欢 提交于 2019-11-27 08:25:44
问题 I'm working with pyomo and already have a model defined, with an objective function to go with it. After the model is solved, the objective function has certain parameters attached to it. So if i had a multi index variable [x1, x2, x3] , my quadratic objective function would suppose look something like this: (x1^2 + 13*x2^2 + 10*x3^2) + (2*x1 +......) . My question is: given that i can actually access this expression in string format from the objective, is there any way to obtain the second

Compute a derivative using discrete methods

余生长醉 提交于 2019-11-26 22:58:48
问题 I am looking for a method to compute a derivative using a discrete and fast method. Since now I do not know the type of equation I have, I am looking for discrete methods analog to the ones that we can find for the integral such as, the Euler method. 回答1: I think you are looking for the derivative calculated in a point. If this is the case, here there is a simple way to do that. You need to know the derivative in a point, say a . It is given by the limit of the difference quotient for h->0:

Find all local Maxima and Minima when x and y values are given as numpy arrays

柔情痞子 提交于 2019-11-26 21:17:34
问题 I have two arrays x and y as : x = np.array([6, 3, 5, 2, 1, 4, 9, 7, 8]) y = np.array([2, 1, 3, 5, 3, 9, 8, 10, 7]) I am finding index of local minima and maxima as follows: sortId = np.argsort(x) x = x[sortId] y = y[sortId] minm = np.array([]) maxm = np.array([]) while i < y.size-1: while(y[i+1] >= y[i]): i = i + 1 maxm = np.insert(maxm, 0, i) i++ while(y[i+1] <= y[i]): i = i + 1 minm = np.insert(minm, 0, i) i++ What is the problem in this code? The answer should be index of minima = [2, 5,