Tutorial: Passing a Function, Function callback
Introduction
In this tutorial, we will learn how to pass a mathematical function f(x) as an input argument to another function.
Find derivative of given function
How can you use myfunc()
within the function of gradientFunc()
that finds the derivative?
myFun(x): returns F(x)= 2x^3
gradientFunc(myfunc): returns 6x^2
Example:
Calling a function within another function
There are several methods of calling a function within another function.
Method 1
Calling the function that is defined globally or in the same scope
Download the demo source files
Method 2 (recommended)
Pass a function as an input argument to another function.
Last updated