Matlab: Numerically Integrate and Plot Response of Underdamped System

In summary, the conversation discusses using MATLAB to numerically integrate and plot the response of an underdamped system with given parameters and initial conditions, as well as an applied force. The attempt at a solution involves defining variables and time durations, using the state space form and the lsim function. However, the program produces an error, possibly related to the initial conditions, and the poster requests advice and asks for any shared Matlab routines for clarification.
  • #1
Northbysouth
249
2

Homework Statement


Numerically integrate and plot the response of an underdamped system determined by m= 100 kg,
k= 20,000 N/m, and c = 200 kg/s, subject to the initial conditions of x0 = 0.01 m and v0 = 0.1 m/s, and the applied force F(t)=150cos(5t). Then plot the exact response.

Homework Equations


The Attempt at a Solution



I've been trying to use MATLAB to solve this question, but I'm having a little trouble. I started by defining the variables and the time durations. I was attempting to use the state space form to solve the problem, hence I defined matrices A, B, C and D

Code:
m=100; k=20000; c=200; x0=0.01; v0=0.1; f0=150; w=5;
F0=f0/m;
t=[0:0.1:5];

A=[0 1; -k/m -c/m];
B=[0; 1];

C=[0 1;1 0];

D=[];

sys=ss(A,B,C,D);

u=F0*cos(w*t);

lsim(sys,u,t,x0,v0)

[code]

When I run the code I get:

Error using DynamicSystem/lsim (line 98)
Invalid syntax for time or frequency response command. See command help for more
information.

Error in ME_3504_chapter2_80a (line 17)
lsim(sys,u,t,x0,v0) 

I don't understand what the problem is. I can see it's to do with lsim, but I'm not sure how to fix it. I suspect that it may have something to do with the initial conditions x0 and v0.

Any advice would be greatly appreciated. Thank you
 
Last edited:
Physics news on Phys.org
  • #2
If you have written Matlab routines to solve your problem, please share them so that we can make sense of the errors you have gotten. Don't forget to use
Code:
 tags for the source.
 
  • #3
I've added the
Code:
 tags but I'm not sure what you mean by Matlab routines.
 
  • #4
Northbysouth said:
I've added the
Code:
 tags but I'm not sure what you mean by Matlab routines.[/QUOTE]

It's not clear if you have written a program in Matlab to solve your problem or you are trying to do it interactively.  You know what you have done; we don't, so we are depending on you to provide the details.

What you have shown in the OP obviously doesn't have a line 98.  Show all the MATLAB programming you are using to solve the problem.  The [CODE] tags should go around that when you attach it as a reply.
 
  • #5
for your question and for sharing your attempt at a solution. It seems like you are on the right track in using the state space form to solve this problem. However, the issue with your code is that you have defined the output matrix C as a 2x2 matrix, which is not valid for the lsim function. The output matrix should be a 1x2 matrix for a single output system. Additionally, you do not need to specify the D matrix as empty, as it is not used in this case.

To fix the error, you can modify your code as follows:

Code:
m=100; k=20000; c=200; x0=0.01; v0=0.1; f0=150; w=5;
F0=f0/m;
t=[0:0.1:5];

A=[0 1; -k/m -c/m];
B=[0; 1];

C=[0 1]; %change to 1x2 matrix

sys=ss(A,B,C,[]); %remove D matrix

u=F0*cos(w*t);

lsim(sys,u,t,[x0 v0]) %specify initial conditions as a 1x2 matrix

[code]

This should solve the error and allow you to plot the response of the underdamped system. Additionally, to plot the exact response, you can use the equation for the underdamped system:

x(t) = e^(-ct/2m) * [A1*cos(wd*t) + A2*sin(wd*t)] + F0/k * cos(w*t)

where wd = sqrt(k/m - c^2/4m^2) is the damped natural frequency and A1 and A2 are constants determined by the initial conditions. You can use the initial conditions to solve for A1 and A2 and then plot the exact response using this equation.

I hope this helps and good luck with your assignment!
 

FAQ: Matlab: Numerically Integrate and Plot Response of Underdamped System

1. What is Matlab?

Matlab is a programming language and interactive environment commonly used in scientific and engineering applications. It allows users to perform numerical computations, visualize data, and create graphical user interfaces.

2. What does it mean to numerically integrate in Matlab?

Numerical integration in Matlab refers to the process of approximating the definite integral of a function using numerical methods. This is often used to solve complex mathematical problems that cannot be solved analytically.

3. How do I numerically integrate a function in Matlab?

To numerically integrate a function in Matlab, you can use the built-in function trapz or quad. These functions take in the function to be integrated, as well as the limits of integration, and return the approximate value of the integral.

4. What is an underdamped system?

An underdamped system is a type of dynamic system that exhibits oscillatory behavior in response to a disturbance, with the oscillations gradually decreasing in amplitude over time. It is commonly found in mechanical and electrical systems.

5. How do I plot the response of an underdamped system in Matlab?

To plot the response of an underdamped system in Matlab, you will first need to define the system's differential equation and specify the initial conditions. Then, you can use the ode45 function to numerically solve the equation and plot the results using the plot function.

Similar threads

Replies
1
Views
3K
Replies
10
Views
2K
Replies
6
Views
2K
Replies
2
Views
1K
Replies
6
Views
1K
Replies
1
Views
3K
Replies
1
Views
2K
Replies
4
Views
3K
Back
Top