How to use Embedded MATLAB Function to calculate the maximum of a single-variable function
1 次查看(过去 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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!