Error: Not enough input arguments

3 ビュー (過去 30 日間)
Jamie Al
Jamie Al 2021 年 5 月 2 日
編集済み: per isakson 2021 年 5 月 2 日
I have the following error in my Runge-Kutta (4 stage) function:
Not enough input arguments.
Error in RK4
for j = 2:N-1 % ERROR HERE
Error in EulerMUSCL (line 94)
[U_RK] = RK4( U_T, Res, dx, dt, k);
My function:
function [ U_RK ] = RK4( U_T, Res, dx, dt, k,N )
%This function returns the consvar and applies 4th order RK.
U_RK = U_T;% size is 8 by 1001 (8 by N)
a = zeros(4,1);
a(1) = 0.25;
a(2) = 1.0/3.0;
a(3) = 0.5;
a(4) = 1.0;
for j = 2:N-1 %ERROR HERE
U_RK(:,j) = U_T(:,j)-a(k)*dt*Res/(dx);
end
end
Why does it say not enough inputs?? Thanks

採用された回答

per isakson
per isakson 2021 年 5 月 2 日
編集済み: per isakson 2021 年 5 月 2 日
Accourding to the definition
function [ U_RK ] = RK4( U_T, Res, dx, dt, k, N )
requires six input values. Your call of the function, RK4
[U_RK] = RK4( U_T, Res, dx, dt, k);
provides only five input values. A value for the last, N, is missing.
  2 件のコメント
Jamie Al
Jamie Al 2021 年 5 月 2 日
Thanks, this definitely was the problem. Now I am having the following error:
Index exceeds the number of array elements (4).
Error in RK4 (line 19)
U_RK(:,j) = U_T(:,j)-a(k)*dt*Res/(dx);
Error in EulerMUSCL (line 94)
[U_RK] = RK4( U_T, Res, dx, dt,N, k);
k here i 4 because it's a 4 stage RK.
per isakson
per isakson 2021 年 5 月 2 日
編集済み: per isakson 2021 年 5 月 2 日
This script returns a <8x100 double>; i.e. it doesn't throw an error.
%%
N = 1e2;
UT = randn( 8, N );
U_RK = RK4( UT, 1, 1e-2, 1e-2, 4, N );
Let me guess, you have switch the order between the inputs k and N. Compare the function declaration and your call-statement.
function [ U_RK ] = RK4( U_T, Res, dx, dt, k, N )
[U_RK] = RK4( U_T, Res, dx, dt,N, k);

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by