Derivatives of vector-valued functions (computing Jacobians)
Contents
Derivatives of vector-valued functions (computing Jacobians)¶
Main message¶
Derivatives of a scalar with respect to a scalar might be relatively straightforward. Derivatives of vector-valued functions are not impossibly difficult. You can use intelligent matrix and array operations to facilitate the process.
from IPython.display import YouTubeVideo; YouTubeVideo('S1Z8_B4tdTQ', width=1024, height=576)
Video transcript available on YouTube and here.
What are vector-valued functions?¶
A vector-valued function is any function that returns multiple values (outputs). These are quite common in engineering models; rarely do we only care about scalar inputs and scalar outputs to a model. Here are some examples of vector-valued functions in the wild:
structural stresses in different members in an aircraft wing
thickness of the tower for a wind turbine from base to top
thrust outputs of an engine at different operating points
altitude of an aircraft along different points in its trajectory
Intuitively, each of these quantities should be considered together, so it makes sense to contain them within a vector or array. You could consider each of them as scalar values, but it would be unreasonably difficult to track them through your model and perform computations efficiently.
In a general sense, think of a “vector” as including arbitrarily dimensioned arrays and tensors. Strictly mathematically, “vector-valued functions” only refer to functions that produce multidimensional outputs, but this lesson is relevant even in the case of multidimensional inputs and single-dimensional outputs. I’ll be covering the general case of arbitrarily sized inputs and outputs.
Here are some three examples of engineering functions that are not scalar-to-scalar.
Angle between two 3D vectors¶
Despite having 6 inputs, because the output is scalar, this is technically not a vector-valued function. It’s still quite a relevant engineering function. Don’t read too much into the proper definition of “vector-valued function” and what’s included or not, just know that in this lesson we’re talking about anything that’s not a scalar-to-scalar function.
Exit velocity of a tennis ball in 2D¶
I’ve got a backyard tennis ball launcher where you can choose the launch angle and speed. Let’s ignore the 3-dimensional aspect of the world right now and think in 2D. This results in a two dimensional input (launch angle and speed) and a two dimensional output for the velocity (x and y components). This is a vector-valued function.
Force-displacement history for an automotive shock absorber¶
Let’s say you’re a suspension engineer for a car company. You are trying to model the displacement of the suspension system across a car’s simulated route. Simplifying a lot of physics, we can obtain the displacement (\(x\)) of the shock absorber by knowing the force (\(F\)) acting on it and the spring constant (\(k\)): \(x = F/k\). Given a recording of force measurements from 1000 timepoints in a lab test, we can compute the corresponding shock displacement at each point.
This results in 1000 inputs and 1000 outputs and this is a vector-valued function.
Brief math theory of derivative arrays (Jacobians)¶
I’ll now detail some basic theory behind the derivatives of vector-valued functions. Sec. 6.1 in Engineering Design Optimization also presents this information.
In the case of a function \(f(x)\) where the input and output are both scalars, we get:
In the general case we have an array called the Jacobian which contains the gradient information for vector-valued functions. Its size is based on the number of inputs \(n_x\) and the number of outputs \(n_f\) as such:
Here is a reproduction of Ex. 6.1 from Engineering Design Optimization to show how to obtain the derivatives of a simple vector-valued function.
Differentiating symbolically, we get:
Evaluating this at \(x=(\pi/4, 2)\) yields
You can think of computing the Jacobian entries as individually computing derivatives of scalars with respect to scalars and putting them in an array. But I would not suggest thinking that way, especially in more complex cases. It’s helpful to know that deep down all vector-valued functions are just scalar functions smashed together. Often times, though, there will be patterns in the derivatives that you should harness when computing Jacobians for vector-valued functions.