Info
此问题已关闭。 请重新打开它进行编辑或回答。
I am Trying to Have User Input a single Var. But I Get This Error? Help?
2 次查看(过去 30 天)
显示 更早的评论
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?
1 个评论
Jan
2017-10-14
What is the problem with the current version? You use y and n as inputs of the function, but overwrite it later.
回答(1 个)
David Ding
2017-10-17
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
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!