MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何在Matlab中记忆递归函数 (https://www.labfans.com/bbs/showthread.php?t=22483)

poster 2019-12-07 02:32

如何在Matlab中记忆递归函数
 
我正在使用Matlab R2018a。它具有一个“记忆”功能,该功能可以在顶层使用,但是我看不到如何将其用于递归功能。例如,我尝试了这个:

function z = recfib(n) if n == 1 z = 1; else z = memfib(n-1)+memfib(n-2); end fprintf('computed f(%d)=%d',n,z); end 然后

memfib = memoize(@recfib); 但这不起作用,因为调用memfib或recfib会产生错误:

未定义的函数或变量“ memfib”。



[url=https://stackoverflow.com/q/59218231]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:28

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.