필터 지우기
필터 지우기

skip parameters in function

조회 수: 6 (최근 30일)
Elena Bertseva
Elena Bertseva 2016년 11월 22일
답변: Star Strider 2016년 11월 22일
Hi! Could you, please, help me to read these lines:
[t,y]=ode15s(@vesicle,t0,x0,options,parameters);
function [t,r]=vesicle(~,x,parameters)
The help says that "~" means one parameter skipped. But the calling function seems to have much more parameters than the function definition. So, which parameters does "~" replace in this case?

답변 (2개)

Guillaume
Guillaume 2016년 11월 22일
The function passed to any of the ode functions must have a specific signature (number of inputs and outputs), since odexxx will call that function with a specific number of arguments and expect in return a specific number of values. However, it's possible that your function does not actually need all the arguments that odexxx gives it. In that case, you can simply ignore these inputs with ~. That's what is done here.
But you are correct, that the function signature of vesicle is not valid. It should only have two inputs and return only one output. You will therefore get an error if you attempt to run the code.
You can parametise the ode function as documented here but adding extra inputs and outputs as is done here is not how it's done.

Star Strider
Star Strider 2016년 11월 22일
In ODE functions, the format is fixed, so that time is always the first argument, and the current value of the function being integrated the second argument. If the function does not use the time variable, is it common to leave it out.
The function would work, for example this works:
qfcn = @(~,x) x.^2;
q1 = qfcn(1, 2)
q2 = qfcn([],3)
The problem is the way ode15s interprets the output of the ‘vesicle’ function, since the ODE function is supposed to return only a column vector of derivatives, and since the default would be to use only the ‘t’ value ‘vesicle’ returns, you might not get the result you want. The ODE integration functions supply their own time values, so calculating them in the ODE function and returning them is not only not necessary, but could cause problems.
I would look at the way ‘vesicle’ is written to be certain it returns what it is supposed to return.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by