Too many Input arguments

1 view (last 30 days)
Moyin
Moyin on 26 Jan 2018
Commented: Moyin on 27 Jan 2018
Hi all,
Can someone please explain when it's appropriate to use ~ when inputting the function arguments. I am a bit confused about this. If there is only one input argument, why can't you just write that without using ~?
I have included the part of my code below where I keep getting the error 'too many input arguments'. For clarity, qistar and k are like constants. I have also initialized dqidt0 in a separate .m script where I run it using an odesolver. dqidt is the differential of qi with respect to time.
%Code
function dqidt= LDF(qi)
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
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 27 Jan 2018
"Can someone please explain when it's appropriate to use ~ when inputting the function arguments."
Sometimes when you write a function, you need to match an existing interface. For example you might be writing a callback function and so need to be able to accept the object and the event data, but your code might not need those inputs. You can use ~ to fill any position on the input list that you expect but whose value you will ignore.
... and sometimes when you write a function and use it for a while, you change the interface and end up not using a particular input any more. Although you could delete the input parameter that you are no longer using, you would have to simultaneously update all of the code that calls your function. That is not always practical, so sometimes you end up using ~ as a place holder so you do not need to modify the calling code.
You do not need to use ~ for a parameter: you can supply a variable name instead. However, the Just In Time compiler can be slightly more efficient when you use ~ .

More Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!