2016-01-23 78 views
0

如何更改输入参数的顺序?对于fncA_approx(),输入自变量是有序的(height, t),这实际上是直观的。如何控制matlabFunction输出的输入参数顺序,以便排列输入参数(t, height)?如何订购生成函数的输入参数

%% 1.10 Torricelli's equation_; %'// 


syms Qua t Area height alf 

% (a) 
%delta_Height = dsolve('Dheight = (3*Qua*((sin(t))^2) - (alf*(1+ height)^1.5))/Area', 'height(0) = 0') 
% (b) 
dHeight_dt = (3*Qua*(sin(t))^2 - alf*(1+ height)^1.5)/Area 
fnca_approx = subs(dHeight_dt, {Area, Qua, alf}, {1250, 450, 150}) 
fncA_approx = matlabFunction(fnca_approx) 
%% 
step = 0.5; 
t = 0:step:10; 
height = ones(size(t)); 
k = 1; 
height(1) = 0; 
while k < length(t) 
height(k + 1) = height(k) + step*fncA_approx(height(k),t(k)); 
k = k+1; 
end; 
height' 

回答

2

documentation

使用Vars参数指定的用于生成MATLAB函数的输入参数的顺序。

syms x y z t 
r = (x + y/2 + z/3)*exp(-t); 
matlabFunction(r,'Vars',{t,x,z,y}) 

ans = 
    @(t,x,z,y)exp(-t).*(x+y.*(1.0./2.0)+z.*(1.0./3.0))