0

我正在使用递归函数,但我想存储 cp 和轴的所有中间值。但我想不通

[cp,axial]=powerCoefficient(nturbines)

function [cp,axial]=powerCoefficient(iturbines)
if iturbines==0
    cp=0;
    axial=0;
else
    syms a
    expression=matlabFunction(4*a*(1-a)^2+(1-2*a)^3*powerCoefficient(iturbines-1));
    diff1=diff(expression,a);
    solution=double(solve(diff1));
    axial=solution(find(solution >0 &solution<1));
    cp = expression(axial);    
end
end

我会很感激一些帮助。提前致谢!

4

1 回答 1

0

我相信这应该可行,但在速度等方面不是最佳的。

[cp, axial] = powerCoefficient(nturbines, cp, axial)

function [cp, axial]=powerCoefficient(iturbines, cp, axial)
   if iturbines == 0
       cp(end + 1) = 0;    % or just (end)
       axial(end + 1) = 0; % or just (end)
   else
       syms a
       expression=matlabFunction(4*a*(1-a)^2+(1-2*a)^3*powerCoefficient(iturbines-1));
       diff1 = diff(expression, a);
       solution = double(solve(diff1));
       axial(end + 1) = solution(find(solution > 0 & solution < 1));
       cp(end + 1) = expression(axial(end + 1);    
   end
end

如果你在这里和那里使用空间,它会更容易阅读 =)

于 2013-11-09T12:35:43.717 回答