我正在使用递归函数,但我想存储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
我很感激一些帮助。提前谢谢!
答案 0 :(得分: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
如果你在这里使用空间,那么它更容易阅读=)