I have below system of equations
Is it possible to solve this with ode45 of matlab? I know that I need to convert the second order equations to two first order ones, but my confusion comes from the term which is the product of derivatives of s and theta .
P.S. Beta is only a constant
I have defined the set of equations as a function as:
function dy = pend(t,y)
beta = 1;
dy(1) = y(2);
dy(2) = -1/(1+y(3))*sin(y(1))-2/(1+y(3))*y(2)*y(4);
dy(3) = y(4);
dy(4) = (1+y(3))*y(2)*y(2)+cos(y(1))-1-beta^2*y(3);
y=y';
end
considering y(1) to be theta, y(2) be derivative of theta, y(3) be s and y(4) be its derivative with respect to time.
Then I solve it using
[t,y] = ode45(@pend,[0 20],[pi/4 ; 0 ; 0 ; 0]);
Yes, it should be possible to solve using ode45
.
Let
theta = x1
s = x2
thetadot = x3
sdot = x4
Then you will have following set of equations:
x1dot = x3
x2dot = x4
x3dot + sin(x1)/(1 + x2) + 2/(1+x2).x4.x3 = 0
x4dot - (1 + x2).(x3)^2 = cos(x1)-1-beta^2*x2
Now give these set of equations for ode45
with initial values for x1
,x2
, x3
and x4
. You need to rewrite 3rd and 4th equation appropriately.
EDIT1:
You have written the system of equations already. So now use
y0 = [pi/4; 0; 0; 0];
tspan = [0 20];
[t,y] = ode45(pend, tspan, y0);
EDIT2:
function dy = pend(t,y)
beta = 1;
dy = [y(2);
-1 / (1 + y(3))*sin(y(1)) - 2/(1 + y(3))*y(2)*y(4);
y(4);
(1 + y(3))*y(2)*y(2) + cos(y(1)) - 1 - beta^2*y(3)];
end
This should work for you.