How do you initialize a nested function?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I'm trying to find the derivative of qi with respect to time and I'm not sure how to initialise qi. The ode function is nested within a parent function (and the parent function is initialised in a separate .m file). Is there a format for initializing nested odes?
A copy of the nested function is shown below:
%Code
function dqidt= LDF1(~,qi)
%This function computes the derivative of qi wrt time
TestProcess_Parameters;
qistar = qsat* bi*P_opt^vi/(1+ bi*P_opt*vi); %Calculate Equilibrium molar loading
k =(15*Dm)/Rc^2; %Mass transfer coefficient for spherical adsorbent pellets
dqidt = k*(qistar - qi);
end
4 件のコメント
Walter Roberson
2018 年 1 月 31 日
You are calling LDF with one parameter, but you are defining LDF with two parameters in which you are ignoring the first. Since you have exclusive control over LDF, it would not seem to make sense to define it as taking two parameters.
採用された回答
Jan
2018 年 1 月 31 日
Usually for odes, it is my understanding that you give the input parameter
an initial value before running the ode solver, something like this:
[t,y] = ode15s(odefun,tspan,y0,options) where y0 is the initial value.
This is almost or partially correct. You do not "give" the function to be integrated an initial value. The initial value is delivered to the integrator, which use it as start point of the trajectory. But you do not "initialized" the function to be integrated.
i get an error of 'not enough input parameters' for the dqidt function and
i think it is because qi does not have an initial value.
Please post the error message instead of a short rephrasing. It contains important information.
No, you do not have to "initialize" the function LDF. As Walter has said already, it is defined with 2 inputs (while the first one is ignored):
function dqidt= LDF(~, qi)
but you callit with 1 input only:
dqidt = LDF(qi);
You need:
dqidt = LDF([], qi);
Or anything else as first input - this does not matter, because it is ignored.
The function LDF computes the derivative of the function. This might depend on the time and the current value, and you provide the current value as qi already, but only at the wrong position in the list of inputs.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!