diff --git a/deriv/deriv.v b/deriv/deriv.v index 2624ce196..41ae63293 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -1,6 +1,7 @@ module deriv import vsl.func +import vsl.errors import vsl.internal.prec import math @@ -114,20 +115,21 @@ pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { return forward(f, x, -h) } +/** +* partial is a function that computes the partial derivative of a multivariable function with respect to a specified variable. +* +* @param f The multivariable function for which the partial derivative is to be computed. +* @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. +* @param variable The index of the variable with respect to which the partial derivative is to be computed. +* @param h The step size to be used in the central difference method. +* +* @return A tuple containing the value of the partial derivative and the estimated error. +*/ pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { - /** - * partial is a function that computes the partial derivative of a multivariable function with respect to a specified variable. - * - * @param f The multivariable function for which the partial derivative is to be computed. - * @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. - * @param variable The index of the variable with respect to which the partial derivative is to be computed. - * @param h The step size to be used in the central difference method. - * - * @return A tuple containing the value of the partial derivative and the estimated error. - */ + if variable < 0 || variable >= x.len { - panic('Invalid variable index') + errors.vsl_panic('Invalid variable index', .efailed) } // Define a helper function that converts the multivariate function