如何为生成的函数排序输入参数
How to order input arguments for a generated function
如何更改输入参数的顺序?对于 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'
Use the Vars
argument to specify the order of input arguments for the generated MATLAB function.
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))
如何更改输入参数的顺序?对于 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'
Use the
Vars
argument to specify the order of input arguments for the generated MATLAB function.
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))