필터 지우기
필터 지우기

Too many input arguments: error in ODE45

조회 수: 3 (최근 30일)
Shreshtha Chaturvedi
Shreshtha Chaturvedi 2022년 12월 18일
댓글: Shreshtha Chaturvedi 2022년 12월 18일
I have the following coefficient matrix my_Xi:
my_Xi =
0 0 0 0 0 0
0 0 0 0 0 0
0 11.3936 0 0 0 0
0 0 0 0 0 0
0 15.7629 0 0 0 0
0 -15.4752 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 49.6849 0 -27.7503 17.9319 10.0351
0 0 0 0 0 0
0 0 0 0 0 0
0 -18.1205 12.0592 28.3871 0 0
0 0 0 0 0 0
0 0 0 -39.3697 0 0
0 55.9200 0 0 26.7242 0
0 0 -19.7125 -43.3555 0 0
0 0 0 80.7743 0 0
0 0 0 0 0 0
0 0 0 17.6067 0 0
0 -15.4446 -23.2459 0 0 0
0 -42.8207 0 0 -21.9576 0
0 20.2546 0 -39.3216 0 0
0 64.4836 0 -22.1828 16.8531 0
0 -23.5016 32.6644 60.2232 0 0
0 45.2034 20.2962 0 18.9374 0
0 0 0 -43.7764 0 0
0 0 0 0 0 0
0 -21.5528 0 23.3698 0 0
I am trying to solve a system of odes with 6 variables:
my_n = 6
my_x0 = [-0.4999;0.2927;-1.8887;-0.8495;-0.4719;-1.4219]
fun = @(x) my_Xi.'* [1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5), x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4), x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6), x(6)*x(6)]
options = odeset('RelTol',1e-12,'AbsTol',1e-12*ones(1,my_n));
my_dt = 0.0083;
my_tspan=[.01:my_dt:(1133)*my_dt];
[t,x]=ode45(fun, my_tspan, my_x0, options);
However, this code gives me the error: "Too many input arguments." Can someone please help?

채택된 답변

Paul
Paul 2022년 12월 18일
Hi Shreshtha,
The function handle input to ode45 needs to take two arguments: t and x. Also, the matrix multiply defined in fun won't work, I'm guessing the vector needs to be transposed to make it compatible wity my_Xi.'.
Code below runs without error.
my_Xi = [
0 0 0 0 0 0
0 0 0 0 0 0
0 11.3936 0 0 0 0
0 0 0 0 0 0
0 15.7629 0 0 0 0
0 -15.4752 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 49.6849 0 -27.7503 17.9319 10.0351
0 0 0 0 0 0
0 0 0 0 0 0
0 -18.1205 12.0592 28.3871 0 0
0 0 0 0 0 0
0 0 0 -39.3697 0 0
0 55.9200 0 0 26.7242 0
0 0 -19.7125 -43.3555 0 0
0 0 0 80.7743 0 0
0 0 0 0 0 0
0 0 0 17.6067 0 0
0 -15.4446 -23.2459 0 0 0
0 -42.8207 0 0 -21.9576 0
0 20.2546 0 -39.3216 0 0
0 64.4836 0 -22.1828 16.8531 0
0 -23.5016 32.6644 60.2232 0 0
0 45.2034 20.2962 0 18.9374 0
0 0 0 -43.7764 0 0
0 0 0 0 0 0
0 -21.5528 0 23.3698 0 0];
my_n = 6;
my_x0 = [-0.4999;0.2927;-1.8887;-0.8495;-0.4719;-1.4219];
% two corrections here
fun = @(t,x) my_Xi.'* [1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5), x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4), x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6), x(6)*x(6)].';
options = odeset('RelTol',1e-12,'AbsTol',1e-12*ones(1,my_n));
my_dt = 0.0083;
my_tspan=[.01:my_dt:(1133)*my_dt];
[t,x]=ode45(fun, my_tspan, my_x0, options);
  댓글 수: 1
Shreshtha Chaturvedi
Shreshtha Chaturvedi 2022년 12월 18일
Hi, thank you! I am unable to accept your answer as it says: "Unable to complete the action because of changes made to the page. Reload the page to see its updated state", even after reloading. I will try again after some time :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by