Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Felix Adamo
Felix Adamo 2017년 10월 14일
마감: MATLAB Answer Bot 2021년 8월 20일
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
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
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

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by