简体   繁体   English

Matlab编码器Fzero函数

[英]Matlab coder fzero function

I am trying to convert a MATLAB code to C code using "MATLAB Coder", but anonymous functions are not allowed. 我正在尝试使用“ MATLAB Coder”将MATLAB代码转换为C代码,但不允许使用匿名函数。

How can I convert for example an fzero function as 我如何将例如fzero函数转换为

myfun = @(x,c) cos(c*x);  % parameterized function
c = 2;                    % parameter
fun = @(x) myfun(x,c);    % function of x alone
x = fzero(fun,0.1)

into a normal function, for instance, to convert the whole code to C. 转换为普通函数,例如将整个代码转换为C。

You have "anonymous" functions, not "undefined" functions, just to clear up the terminology. 您具有“匿名”功能,而不是“未定义”功能,只是为了清除术语。

To convert the following to a named function: 要将以下内容转换为命名函数:

myfun = @(x,c) cos(c*x);  % parameterized function

write this: 写这个:

function result = myfun(x,c)

result = cos(c*x);

end

For the second function, write this: 对于第二个函数,编写如下:

function result = myfun2(x)
c = 2;
result = cos(c*x);

end

Finally, call fzero like this: 最后,像这样调用fzero:

x = fzero(@myfun2, 0.1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM