| CAGE User's Guide | ![]() |
About the Worked Example Optimization Algorithm
mbcweoptimizer is an example of a user-specified optimization that solves the following problem:
max TQ over (AFR, SPK) at a given (N, L) point.
[bestafr,bestspk]=mbcweoptimizer(TQ, speed, load) finds a maximum (bestafr,bestspk) to the function TQ.
TQ must be a function (or a function handle) that depends on AFR, SPK, SPEED, and LOAD only. The function must depend on the variables in that order. This routine does no variable matching.
TQ, speed, load, afrrng, spkrng) finds a maximum (bestafr,bestspk) to the function TQ.
TQ, speed, load, afrrng, spkrng, res) finds a maximum (bestafr,bestspk) to the function TQ.
This optimization is performed over a res-by-res grid of (AFR, SPK) values. If res is not specified, the default grid resolution is 100.
TQ, speed, load, afrrng, spkrng, res, optimstore) finds a maximum (bestafr,bestspk) to the function TQ within a CAGE optimization function.
optimstore is passed to this function when it is called from the Evaluate section subroutine of your optimization function. In this case, TQ must be a function handle that takes the inputs AFR, SPK, SPEED, LOAD, and OPTIMSTORE, in that order.
The Structure of the Worked Example
The best way to understand how to implement an external optimizer in a CAGE optimization function is to study the details of the example.
The following code section is taken from the Evaluate section of the worked example file as an example.
The line of code labeled A above calls the worked example optimization algorithm external to the optimization function. As with functions in the Optimization Toolbox, the first argument to the call to the optimizer is a function handle that evaluates the objectives at a given input point. We recommend you place the function pointed at by the function handle in the optimization file. If you do not place them in the same file you must make sure the evaluate function M-file is on the MATLAB path. As an example, the optimization evaluation function in the worked example optimization is shown in the code fragment following.
The first four inputs to this function are the torque (in this case) model inputs. The final input is the optimstore object, where information about the optimization is stored. To evaluate objectives, there are two possible functions from the optimstore object that can be used -- evaluate or gridevaluate. In the above example, the line of code referenced by B evaluates the torque model in the worked example at the (afr, spk, speed, load) input points.
The two subfunctions presented above are an example of how to implement an external optimizer in a CAGE optimization M-file.
See also the tutorial section Creating an Optimization from Your Own Algorithm. This example describes in detail the steps involved in incorporating an example algorithm into a CAGE optimization M-file.
| Checking User-Defined Optimizations into CAGE | Optimization Template | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |