How to use Embedded MATLAB Function to calculate the maximum of a single-variable function

조회 수: 4 (최근 30일)
Good afternoon.
I'd like to know how to use Embedded MATLAB Function to calculate the maximum of a single-variable function, that is, if the function is y=f(x), I want to calculate [xmax, ymax]. I have made a m-file and it works when I run it from MATLAB, but when I type all the code in the Embedded MATLAB Function block, it doesn't work.
-----------------------------------------------------------------------------------------------------------
function [Cpopt,TSRopt]=optimo(beta)
Cp=@(lambda) -0.5176*(116*(1/(lambda+0.08*beta)-0.035/(beta^3+1))-0.4*beta-5)*exp(-21*(1/(lambda+0.08*beta)-0.035/(beta^3+1)))-0.0068*lambda;
TSRopt=fminbnd(Cp,0,14);
Cpopt=0.5176*(116*(1/(TSRopt+0.08*beta)-0.035/(beta^3+1))-0.4*beta-5)*exp(-21*(1/(TSRopt+0.08*beta)-0.035/(beta^3+1)))+0.0068*TSRopt;
-----------------------------------------------------------------------------------------------------------
This code should calculate the maximum of Cp=Cp(lambda), [lambda_opt, Cp_opt]. It seems that this block doesn't recognize "fminbnd" or the structure "function=@(variable).....".
NOTE: To calculate the maximum of Cp using "fminbnd" I have to calculate the minimum of -Cp.
Regards!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by