Volume 9, Issue 2
Tricks of the Trade
In and Out
Download This Issue
In and Out
Q: Consider the following initial-value problem.
The differential equation cannot be solved explicitly so you have to use NDSolve. How can I use the output of NDSolve as the model function argument to NonlinearRegress?
A: Carl Woll (email@example.com) writes: Basically, there are four steps.
1. Define the model with both the parameters and variables restricted to numeric quantities to prevent NDSolve from being given symbolic input.
2. Compute the derivatives of the model with respect to each parameter.
3. Teach Mathematica about these derivatives.
4. Use NonlinearRegress as usual.
After restricting the input parameters and to be numeric quantities, numerical solution is straightforward. The variable used inside NDSolve is in a Module to ensure that it does not already have a value. Dynamic programming improves efficiency by computing and saving the solution for fixed and .
Plot the solution for and .
Next, compute the derivatives of with respect to the parameters and , by differentiating the parameters of the differential equation and the initial condition.
Then use NDSolve on the system of ordinary differential equations, consisting of the original and the differentiated equations.
After you have computed the derivatives of the model with respect to the parameters, teach Mathematica this information.
Next, use NonlinearRegress in the usual way. Load the package.
Create some noisy data.
Then run NonlinearRegress.
View the best-fit solution.
This method allows you to use the full power of NonlinearRegress in a simple and very natural way. There are other approaches, but most of them require that you either use the FindMinimum method of NonlinearRegress, or that you abandon NonlinearRegress (and all of its statistical feedback) and use FindMinimum directly.
About Mathematica | Download Mathematica Player
Copyright © Wolfram Media, Inc. All rights reserved.