2016-01-23 30 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))