我想自动创建依赖于不同变量的多个符号函数,我试过:
% symbolic variables
for k = 1:3
X(k) = sym(sprintf('X%d', k));
Y(k) = sym(sprintf('Y%d', k));
end
% multiple functions
for k = 1:2
f1(k) = @(X(k+1),X(k))(X(k+1) - X(k));
% so, f1(1) is a function of X2 and X1
f1_save(k) = f1;
end
f1_fun(X) = f1_save; %% turn it back into a symbolic funciton
但问题是:
>> f1_fun
f1_fun(X1, X2, X3) =
[ X2 - X1, X3 - X2]
和f1_fun
是1 X 1
'symfun'
而不是1 X 2
'symfun'
。
有什么想法吗?