Too many input arguments: error in ODE45
17 views (last 30 days)
Show older comments
Shreshtha Chaturvedi
on 18 Dec 2022
Commented: Shreshtha Chaturvedi
on 18 Dec 2022
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?
0 Comments
Accepted Answer
Paul
on 18 Dec 2022
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);
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!