Input struct in function
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
When I try to run a function that needs constants defined in a struct outside of it, it give the error "Not enough input arguments.". How can I give as input in the function the data struct?
data.fluid.rho = 890;
data.accumulator.V_N2 = 10e-3;
data.accumulator.P_N2 = 2.5e6;
data.accumulator.p0 = 21e6;
data.accumulator.gamma = 1.2;
data.delivery.D23 = 1;
function dydt = problem(t,y,data)
A23 = (data.delivery.D23^2/4)*pi;
end
This is just an example with some line of codes, I get an error on A23, not enough input arguments. I suspect the function doesnt know what data.delivery.D23 is even if its written outside, how can I pass the data structure in the function?
3 comentarios
Matt J
el 31 de Oct. de 2021
The error is not caused by anything in the code you've shown us. It is caused by the code where problem() is actually invoked.
Nader Mohamed
el 1 de Nov. de 2021
Editada: Nader Mohamed
el 1 de Nov. de 2021
Respuestas (1)
Sulaymon Eshkabilov
el 31 de Oct. de 2021
data.fluid.rho = 890;
data.accumulator.V_N2 = 10e-3;
data.accumulator.P_N2 = 2.5e6;
data.accumulator.p0 = 21e6;
data.accumulator.gamma = 1.2;
data.delivery.D23 = 1;
% A few things are missing:
t = ... % initialize t
y = ... % initialize y
function dydt = problem(t,y,data)
A23 = (data.delivery.D23^2/4)*pi;
dydt = ... % Define dydt
end
2 comentarios
Walter Roberson
el 1 de Nov. de 2021
options = odeset('RelTol',1e-9,'AbsTol',1e-9,'Events',@event);
[tt,yy] = ode15s(@(t,y)problem(t,y,data),[t0,tf],[0,0,1e-3,data.accumulator.Vf],options);
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!