Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.4.0 - Português

Change language to:
English - Français - 日本語 - Русский

Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Ajuda Scilab >> Equações Diferenciais > numdiff


numerical gradient estimation

Calling Sequence

g = numdiff(fun, x [,dx])



an external, Scilab function or list. See below for calling sequence, see also external for details about external functions.


a vector, the argument of the function fun.


a vector, the finite difference step. Default value is dx=sqrt(%eps)*(1+1d-3*abs(x)).


a vector, the estimated gradient.


Given a function fun(x) from R^n to R^p computes the matrix g such as

g(i,j) = (df_i)/(dx_j)

using finite difference methods. Uses an order 1 formula.

Without parameters, the function fun calling sequence is y=fun(x), and numdiff can be called as g=numdiff(fun,x). Else the function fun calling sequence must be y = fun(x, param_1, pararm_2, ..., param_q). If parameters param_1, param_2, ..., param_q exist then numdiff can be called as follow g=numdiff(list(fun, param_1, param_2, ..., param_q), x).

See the derivative with respect to numerical accuracy issues and comparison between the two algorithms.


// example 1 (without parameters)
// myfun is a function from R^2 to R: (x(1),x(2)) |--> myfun(x)
function f=myfun(x)

x=[5 8]

// The exact gradient (i.e derivate belong x(1): first component
// and derivate belong x(2): second component) is
exact=[2*x(1)+x(2)  x(1)]

//example 2 (with parameters)
// myfun is a function from R to R: x(1) |--> myfun(x)
// myfun contains 3 parameters: a, b, c
function f=myfun(x, a, b, c)

a=3; b=4; c=2;

// The exact gradient, i.e derivate belong x(1), is :

See Also

  • optim — non-linear optimization routine
  • derivative — approximate derivatives of a function
  • external — objeto Scilab, função ou rotina externa
Report an issue
<< bvode Equações Diferenciais Funções Elementares >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Oct 01 17:39:43 CEST 2012