Not understanding why I get "too many input arguments error" for anonymous funtion
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am working on a system of differential algebraic equations. The following is my script
% Specify independent variables and state variables by using syms.
syms('E(t)','N(t)','V(t)','A(t)')
syms('sigmaV','gammaV','alpha_2','beta_1','alpha_1','b','beta_2','k')
eqn1 = diff(E(t),1) ==(sigmaV - gammaV)*E(t) + alpha_2*gammaV - beta_1*E(t)*V(t) - alpha_1*sigmaV;
eqn2 = diff(N(t),1) ==(sigmaV - gammaV)*N(t) - beta_2*N(t)*E(t);
eqn3 = diff(V(t),1) ==(sigmaV - gammaV)*V(t) - k*beta_1*V(t)*A(t);
eqn4 = diff(A(t),1) ==(sigmaV - gammaV)*A(t) + (1-alpha_2)*gammaV + beta_1*E(t)*V(t) + beta_2*N(t)*E(t) - k*beta_1*A(t)*V(t) - (1-alpha_1)*sigmaV;
eqn5 = E(t) + N(t) + V(t) + A(t) == 1;
eqns = [eqn1; eqn2; eqn3; eqn5]; % eqn4;
vars = [E(t), N(t), V(t), A(t)];
[eqns, vars, newVars] = reduceDifferentialOrder(eqns, vars);
origVars = length(vars);
M = sum(incidenceMatrix(eqns,vars),1);
unusedVar = M(M==0)
[DAEs,DAEvars] = reduceDAEIndex(eqns,vars);
pDAEs = symvar(eqns);
pDAEvars = symvar(vars);
extraParams = setdiff(pDAEs,pDAEvars);
f = daeFunction(eqns, vars, extraParams);
alpha_1 = 0.0606615; %
alpha_2 = -0.0339111;
k = 0.460359;
beta_1 = 0.869563;
beta_2 = 0.997438;
gammaV = 0.0372;
sigmaV = 0.0194;
% Initial conditions
E_0 = 0.278466;
N_0 = 0.233303;
V_0 = 0.0967287;
A_0 = 0.391502;
paramStr = [sprintf('%s, ',string(extraParams(1:end-1))), ...
char(extraParams(end))];
F = eval(['@(t,Y,YP) double(f(t,Y,YP,' paramStr '))']);
y0est = [E_0; N_0; V_0; A_0];
yp0est = zeros(3,1);
options = odeset('RelTol',1e-4,'AbsTol',[1e-6 1e-6 1e-6 1e-6], ...
'Jacobian',{[],[eye(3) zeros(3,1); zeros(1,4)]});
[y0, yp0] = decic(F,0,y0est,[],yp0est,[],options)
I have been through the function and have satisfied myself that the variables in the symengine expression are as follows
in2(1,:) = y(1) = E(t)
in2(2,:) = y(2) = V(t)
in2(3,:) = y(3) = N(t)
in2(4,:) = y(4) = A(t)
in3(1,:) = yp(1) = diff(E(t), 1)
in3(2,:) = yp(2) = diff(N(t), 1)
in3(3,:) = yp(3) = diff(V(t), 1)
in4(:,7) = sigmaV
in4(:,6) = k
in4(:,5) = gammaV
in4(:,4) = beta_2
in4(:,3) = beta_1
in4(:,2) = alpha_1
in4(:,1) = alpha_2
Not sure why I am being told I have too many variables since everything is accounted for.
I would be greatful if anyone finds what I have missed.
0 commentaires
Réponse acceptée
Walter Roberson
le 5 Août 2022
f = daeFunction(eqns, vars, extraParams);
when you pass in a vector of variable names after the vars in daeFunction, everything in the vector gets bundled into the same input. To be consistent with how you invoke the function later, you need to use the daeFunction(eqns, vars, p1, p2, p3, ... pn) form
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!