How can I solve a 2nd order ODE in matrix form using Matlab?

In summary, the speaker is trying to solve a 2nd order differential equation in matrix form using Matlab, but is having trouble with the ode45 function. They are seeking help with their equation, which involves converting it to a system of 4 coupled 1st order equations. They have been referred to a tutorial on how to rewrite equations as a system of first-order ODEs.
  • #1
intrinsik
1
0
I'm trying to solve a 2nd order differential equation in matrix form. I'm not familiar with Matlab, and have tried solving this using tutorials on youtube.
Initially, theta1 = pi/4, theta2 = 7*pi/12, theta1_d = 0, and theta2_d =0. Time interval is (0,1.2).
When I try to solve this using ode45, I keep getting an error in my equation for dy (last line of function), and I'm not sure what I'm doing wrong. Can anyone help me out?

The equation I'm trying to solve is of the form
A*[theta1_dd;theta2_dd] + B*[theta1_d;theta2_d] = C
where theta1_d is the first derivative of theta, theta1_dd is the second derivative of theta, etc.

function dy = ode(t,y)
m1=2.52;
m2=1.30;
l1=0.33;
l2=0.32;
r1=l1/2;
r2=l2/2;
ic1=(m1*l1^2)/12;
ic2=(m2*l2^2)/12;
i1=ic1+(m1*r1^2);
i2=ic2+(m2*r2^2);
syms theta1 theta2 theta1_d theta2_d theta1_dd theta2_dd t1 t2;
A=[i1+(m2*l1^2), m2*r2*l1*cos(theta2-theta1);m2*r2*l1*cos(theta2-theta1), i2]
B=[0,-m2*r2*l1*sin(theta2-theta1)*theta2_d;-m2*r2*l1*sin(theta2-theta1)*theta1_d,0]
C=[t1-t2;t2]
u1=y(1);
u2=y(2);
dy=[u2;(C/A)-((B/A)*u2)];
end
 
Last edited:
Physics news on Phys.org
  • #2
If you have two coupled 2nd order equations, you need to convert to a system of 4 coupled 1st order equations.
 
  • #3
http://www.mathworks.com/help/matlab/math/ordinary-differential-equations.html

As DrClaude mentioned, see the section "Higher Order ODEs" under "Initial Value Problems" to see how to rewrite the equations as an equivalent system of first-order ODEs. The first example shows how to do this with the van der Pol equation.
 

1. What is a second order ODE in Matlab?

A second order ODE, or ordinary differential equation, in Matlab is a mathematical equation that describes the relationship between a function and its derivatives. It is of the form y'' = f(x,y,y'), where y' represents the first derivative and y'' represents the second derivative of the function y with respect to the independent variable x.

2. How do I solve a second order ODE in Matlab?

To solve a second order ODE in Matlab, you can use the built-in function ode45. This function implements the Runge-Kutta method to numerically solve the ODE. All you need to do is provide the function f(x,y) and initial conditions for y and y'.

3. Can I plot the solution of a second order ODE in Matlab?

Yes, you can plot the solution of a second order ODE in Matlab using the plot function. You can also use the fplot function to plot the solution over a specified range of x values.

4. Can I change the order of a differential equation in Matlab?

Yes, you can change the order of a differential equation in Matlab by using the subs function. This function allows you to substitute variables and expressions in an equation. By substituting y'' with a new variable, you can effectively change the order of the equation.

5. What are the boundary conditions for a second order ODE in Matlab?

The boundary conditions for a second order ODE in Matlab depend on the specific problem you are trying to solve. However, in general, you will need to provide initial conditions for the function y and its first derivative y'. These can be specified as values at a single point or as a range of values.

Similar threads

Replies
2
Views
599
  • Engineering and Comp Sci Homework Help
Replies
1
Views
800
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Advanced Physics Homework Help
Replies
2
Views
3K
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
7K
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
9K
Back
Top