not enough input arguments when using function functions.

1 回表示 (過去 30 日間)
Arthur
Arthur 2024 年 6 月 12 日
コメント済み: Ganesh 2024 年 6 月 12 日
Hi, when I call heun(u0,n,dt,f), the error is:
Not enough input arguments.
Error in f (line 7)
mat = zeros(n);
Any ideas why? It's like the f function hasn't even read the parameters I put into it.
Thanks.
  2 件のコメント
Stephen23
Stephen23 2024 年 6 月 12 日
編集済み: Stephen23 2024 年 6 月 12 日
Please show the exact code used to define the inputs u0, n, dt, and f, and exactly how you call heun. Do not edit anything to make it simpler for us, we need the exact code.
Most likely you called the function instead of defining a function handle:
Arthur
Arthur 2024 年 6 月 12 日
Hi, that was exactly the issue. Thanks!

サインインしてコメントする。

回答 (1 件)

Ganesh
Ganesh 2024 年 6 月 12 日
編集済み: Ganesh 2024 年 6 月 12 日
The error is occuring as you are likely not passing "f" as a "function handle".
You can try calling "heun(u0,n,dt,@f)" instead.
When passing functions as arguments to another function, it is important to pass it as a function handle always. You can find more on "function handles" from the following documentation:
Edit - I just saw @Stephen23 has already answered it in comments, apologies for a repetitive answer.
  2 件のコメント
Arthur
Arthur 2024 年 6 月 12 日
that was exactly the issue. Thanks!
Ganesh
Ganesh 2024 年 6 月 12 日
Kindly accept the answer if your query is resolved!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by