To find the maximum of sin(x)*e^-x in Matlab, we can use the built-in optimization function fminbnd
combined with the function handle for our objective function.
Here's an example code snippet:
main.m255 chars13 lines
This code sets up the objective function f(x)
, defines the lower and upper bounds for our search area, and then calls fminbnd
to find the maximum value and corresponding x-value. Finally, the code prints out the result.
Note that we negate the result of fminbnd
since we want to find the maximum, but fminbnd
finds the minimum.
gistlibby LogSnag