skip parameters in function

12 Ansichten (letzte 30 Tage)
Elena Bertseva
Elena Bertseva am 22 Nov. 2016
Beantwortet: Star Strider am 22 Nov. 2016
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?

Antworten (2)

Guillaume
Guillaume am 22 Nov. 2016
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 am 22 Nov. 2016
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.

Community Treasure Hunt

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

Start Hunting!

Translated by