Info

# I am Trying to Have User Input a single Var. But I Get This Error? Help?

2 views (last 30 days)
Felix Adamo on 14 Oct 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
function [Y,T]=coopiem(t,tf,y,n)
prompt='Please enter a parameter, k: ';
t=0;
tf=24;
k=input(prompt);
y=yofk(k); %when k=0.2
n=36;
Y=y;
T=t;
h=(2/3);
for i=1:n; %figure how to do the interations
ye=y+(f(t,y))*h;
y=y+(1/2)*(f(t,y)+f((t+h),ye))*(2/3);
t=t+h;
Y=[Y;y];
T=[T;t];
Q=transpose([t;y]);
disp(Q);
end
I want to prompt the user to input a parameter k. But my initial y value (y0) is a function of k, because my initial time t (t0) is zero. How can I make it work?
Jan on 14 Oct 2017
What is the problem with the current version? You use y and n as inputs of the function, but overwrite it later.

David Ding on 17 Oct 2017
Hi Felix,
I understand that you are receiving a "Not Enough Input Arguments" error. While I am not in a position to comment on the content of your code, I can point out that you are receiving your error because of your function "f.m". In "f.m", you are specifying three input arguments: "t", "y" and "k" as shown in the function declaration:
function coopiem = f(t, y, k)
However, in your script shown, you are calling "f" as follows:
f(t, y)
This will yield the error because you are calling "f" with two input arguments but it is expecting three. You need to supply the third argument, presumably some value corresponding to your "k".
Hope this helps,
David