How to solve 2nd order ODE with matrix parameters in Matlab

In summary: If I am going for more iterations, however, then the xj portion will be lengthened, right?) However, I am still a bit puzzled in how I can solve this for a matrix of k and c values (since m will be multiplied through by the inverse method)- for example, in row 1 column 1 of the tridiagonal matrix, I will be multiplying by 2+delT*q_1, where q_1 stands for the c matrix corresponding at a certain time. So will my tridiagonal matrix involve another matrix multiplication? Also, your earlier assumption is correct in
  • #1
iqjump123
61
0

Homework Statement



I have a frequency equation to solve for the displacement for a spring mass damper truss system, as seen below,

[m]u''+[c]u'+[k]u=f(t),
where m,c,k, are all matrices (2x2), and f(t) is a graph-defined forcing function. I am to use 3 nodes, using the central difference approximation method.

I am to solve for the displacement and the time history of the displacement.

Homework Equations



What I have learned so far involved solving matrix equations using [A]{x}={b}

The Attempt at a Solution


I am just confused as to the basic concepts- I should have to be able to decouple this equation, because this is essentially trying to solve a space and time dependent problem.

I am not sure how I can solve for this, and also doing that using the CDM- I would presume that I would somehow solve for the displacement at each time "point", but do i have to use the CDM to solve for the displacements as well? If that is the case, how can I solve the equation that involves matrices and not values?

any help to get me started will be of immense help.

thanks!
 
Physics news on Phys.org
  • #2
iqjump123 said:
[m]u''+[c]u'+[k]u=f(t),
where m,c,k, are all matrices (2x2), and f(t) is a graph-defined forcing function. I am to use 3 nodes, using the central difference approximation method.


There is something wrong there. If you have 3 nodes your matrices should be 3x3 not 2x2.

Or do you mean "there are 3 nodes in the structure, but one of them is fixed, so it can be eliminated."

I am just confused as to the basic concepts- I should have to be able to decouple this equation, because this is essentially trying to solve a space and time dependent problem.
Start by understanding how to use CDM for a system with just one variable, for example a mass oscillating on a spring.

You get an equation that says [itex]x_{t+h}[/itex] = something involving [itex]x_t[/itex], [itex]x_{t-h}[/itex], f(t), and k c and m.

For a system with several degrees of freedom, you use exactly the same equation, except x and f are vectors and k c and m are matrices. The only difference is that instead of dividing by a scalar value of m, you multiply by the inverse matrix [itex]m^{-1}[/itex].

CDM is often used when the mass matrix m is diagonal, and inverting a diagonal matrix is easy.
 
  • #3
AlephZero said:
There is something wrong there. If you have 3 nodes your matrices should be 3x3 not 2x2.

Or do you mean "there are 3 nodes in the structure, but one of them is fixed, so it can be eliminated."


Start by understanding how to use CDM for a system with just one variable, for example a mass oscillating on a spring.

You get an equation that says [itex]x_{t+h}[/itex] = something involving [itex]x_t[/itex], [itex]x_{t-h}[/itex], f(t), and k c and m.

For a system with several degrees of freedom, you use exactly the same equation, except x and f are vectors and k c and m are matrices. The only difference is that instead of dividing by a scalar value of m, you multiply by the inverse matrix [itex]m^{-1}[/itex].

CDM is often used when the mass matrix m is diagonal, and inverting a diagonal matrix is easy.
Hey alephzero,

Thanks so much for your help. It definitely helped in me understanding the approach. I have been consulting some numerical methods handbooks to get myself familiar with when mck are single variables. It seems that I will have to build a tri-diagonal matrix and make it solve for a vector of x values(it seems at the very minimum, I will need x1, x2, xj, xn-2 xn-1 values, with j being the iteration i am solving for, and n-1 being the last iteration. If I am going for more iterations, however, then the xj portion will be lengthened, right?)


However, I am still a bit puzzled in how I can solve this for a matrix of k and c values (since m will be multiplied through by the inverse method)- for example, in row 1 column 1 of the tridiagonal matrix, I will be multiplying by 2+delT*q_1, where q_1 stands for the c matrix corresponding at a certain time. So will my tridiagonal matrix involve another matrix multiplication?

Also, your earlier assumption is correct in that my problem requires a 3 node system. Then the way to solve that is to iterative this code 3 times for the 3 different node and force locations, is that correct?

thanks, as always.

iqjump123
 
  • #4
iqjump123 said:
Hey alephzero,

Thanks so much for your help. It definitely helped in me understanding the approach. I have been consulting some numerical methods handbooks to get myself familiar with when mck are single variables. It seems that I will have to build a tri-diagonal matrix and make it solve for a vector of x values(it seems at the very minimum, I will need x1, x2, xj, xn-2 xn-1 values, with j being the iteration i am solving for, and n-1 being the last iteration. If I am going for more iterations, however, then the xj portion will be lengthened, right?)

You seem be getting confused about the the number of variables at different points in space, and the values of their displacement at diffferent times.

If you have a single variable problem like a mass on a spring, the equation of motion equation is mu'' + cu' + ku = f(t)

You convert that into an equation connecting the values of x at three different times, using difference approximations. Call the three times t-h, t, and t+h where h is the time step.

You can approximate u'(t) by [u(t+h) - u(t-h)] / 2h
and u''(t) by [u(t+h) - 2u(t) +u(t-h)] / h^2

So the finite difference version of the equation of motion is

m [u(t+h) - 2u(t) +u(t-h)] / h^2 + c [u(t+h) - u(t-h)] / 2h + k u(t) = f(t)
or
m [u(t+h) - 2u(t) +u(t-h)] + (ch/2) [u(t+h) - u(t-h)] + kh^2 u(t) = h^2 f(t)

As you work through the solution, you already know u(t) and u(t-h) so you can rearrange this to find u(t+h)

[m + ch/2] u(t+h) = (2m - kh^2) u(t) + (-m + ch/2) u(t-h) + h^2 f(t)

If you are starting from t = 0, the initial conditons give you the values of u(0) and u'(0).
To get the calculation started you need the values of u(0) and u(-h). One way to get u(-h) is use a Taylor series approximation and say
u(-h) = u(0) - h u'(0).

So the first time step of the CDM is to calculate u(h) from
[m + ch/2] u(h) = (2m - kh^2) u(0) + (-m + ch/2) u(-h) + h^2 f(0)
For the next time steps, you calculate
[m + ch/2] u(2h) = (2m - kh^2) u(h) + (-m + ch/2) u(0) + h^2 f(h)
[m + ch/2] u(3h) = (2m - kh^2) u(2h) + (-m + ch/2) u(h) + h^2 f(2h)
etc.
You don't need to make one big set of equations for all the time steps.

If you have more than 1 variable (3 in your case), at each step you have to solve a 3x3 set of equations. The equation
[m + ch/2] u(t+h) = (2m - kh^2) u(t) + (-m + ch/2) u(t-h) + h^2 f(t)
is a matrix equation like Au(t+h) = b, where A = m + ch/2. You have to do the matrix multiplcations on the right hand side to calculate the vector b, and then solve the simultaneous equations for u(t+h).

Note, in my first post I said you just needed to invert m. Sorry, I forgot you had the damping matrix c in your model so that wasn't quite right.
 
  • #5




To solve a second order ODE with matrix parameters in Matlab, you can use the "ode45" function. This function solves systems of differential equations numerically using the fourth and fifth order Runge-Kutta method. The syntax for the "ode45" function is as follows:

[T,Y] = ode45(odefun,tspan,y0)

Where "odefun" is a function that describes the system of equations, "tspan" is a vector of time points at which you want to evaluate the solution, and "y0" is the initial condition. In your case, the system of equations can be written as:

u' = v
v' = -inv(m)*(c*v + k*u) + inv(m)*f(t)

Where u is the displacement and v is the velocity. You can create a function that describes this system of equations, and then use the "ode45" function to solve it. The output of the "ode45" function will be a matrix of time points (T) and a matrix of corresponding solutions (Y). You can then plot the displacement over time using the "plot" function in Matlab.

As for using the central difference approximation method, you can use it to approximate the derivatives in your system of equations. The central difference approximation for the first derivative is given by:

f'(x) ≈ (f(x+h) - f(x-h)) / (2*h)

Where h is a small step size. You can use this approximation to replace the derivatives in your system of equations and then solve it using the "ode45" function. This will give you an approximate solution for the displacement and velocity at each time point.

I hope this helps you get started on solving your problem. Remember to always check your results and make sure they make sense in the context of your problem. Good luck!
 

1. How do I define the matrix parameters in Matlab for a 2nd order ODE?

To define the matrix parameters in Matlab for a 2nd order ODE, you can use the "syms" function to declare symbolic variables for each element of the matrix. Then, use the "subs" function to substitute the symbolic variables with the actual values of the matrix parameters.

2. What is the syntax for solving a 2nd order ODE with matrix parameters in Matlab?

The syntax for solving a 2nd order ODE with matrix parameters in Matlab is "dsolve('y''=A*y', 'y(0)=y0', 'y''(0)=y1')", where A is the matrix of parameters, y0 is the initial value of the function, and y1 is the initial value of the derivative of the function.

3. Can I solve a 2nd order ODE with matrix parameters using the "ode45" function in Matlab?

Yes, you can solve a 2nd order ODE with matrix parameters using the "ode45" function in Matlab. However, you will need to convert the ODE into a system of first order ODEs before using the "ode45" function.

4. How do I plot the solution of a 2nd order ODE with matrix parameters in Matlab?

To plot the solution of a 2nd order ODE with matrix parameters in Matlab, you can use the "ezplot" function. First, solve the ODE using the "dsolve" function and then use the "ezplot" function to plot the solution.

5. Is it possible to solve a 2nd order ODE with a matrix parameter that is a function of time in Matlab?

Yes, it is possible to solve a 2nd order ODE with a matrix parameter that is a function of time in Matlab. You can use the "syms" function to declare a symbolic variable for the time, and then use the "subs" function to substitute the symbolic variable with the actual time values before solving the ODE.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
708
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
993
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
223
  • Linear and Abstract Algebra
Replies
6
Views
414
  • Engineering and Comp Sci Homework Help
Replies
2
Views
789
  • Calculus and Beyond Homework Help
Replies
4
Views
438
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Differential Equations
Replies
2
Views
1K
Back
Top