I'm looking for way to solve this differential equations.
I've got small experience solving this type of equations, so here's my noob code
function lab1()
[t,h]=ode45('threepoint', [0 1000], [0 0.25]);
plot(t, h);
function f = threepoint(x, y)
%THREEPOINT Summary of this function goes here
% Detailed explanation goes here
m = 15000;
R1 = 0.1;
R2 = 0.1;
P1 = 0.1;
P2 = 0.1;
B = 4;
rbk = 0.5;
f=[x(6);
x(7);
x(8);
x(9);
x(10);
(-x(6) / (m * sqrt( x(6)*x(6) + x(7)*x(7)))) * (R1 + R2) + (cos(x(3))/m) * P1 + (cos(x(3))/m) * P2;
(-x(7) / (m * sqrt( x(6)*x(6) + x(7)*x(7)))) * (R1 + R2) + (cos(x(3))/m) * P1 + (cos(x(3))/m) * P2;
-(M/I) - (1/I1)* (B/2 + y(1))*P1 + (1/I2)*(B/2+y(2))*P2;
(rbk/I1)*(P1-R1);
(rbk/I2)*(P2-R2);
];
end
While running these functions I have got such errors like
Index exceeds matrix dimensions.
Error in threepoint (line 11) f=[x(6);
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in lab1 (line 2) [t,h]=ode45('threepoint', [0 1000], [0 0.25]);
Can anyone please show me where am I mistaken and how can I fix these errors? Thank you in advance!
Please take a close look at help ode45
. I admit this part of the usage might not be clear, so take a look at doc ode45
too.
Here's the essence of your problem. You want to solve a differential equation of 10 variables, each a function of t
. So, how does a general solver like ode45
know that it needs to work with 10-component arrays at each time step? From the only place it can: the initial value!
Here's how you're calling ode45
:
[t,h]=ode45('threepoint', [0 1000], [0 0.25]);
The second array, Y0
, is the initial value. This is clear from the docs. Since you're supplying a 2-element vector, ode45
smartly realizes that you have only 2 equations. When you try to use Y(6)
and other high-index values in threepoint()
, you get the error you're getting: Index exceeds matrix dimensions. Because your index, 6
, exceeds the size of the array, which is 2
.
You always need to use initial values with the proper size (length-10 in your specific case) in order to inform the solver about the dimensions of your problem. Even if ode45
could assert the size of your equations from somewhere, you really have to provide initial values for all 10 components of your solution.