










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Files that contain code in MATLAB language are called M-Files. You create a M-File using a text editor and then use them as you would any other MATLAB function or command. But before using the user defined functions always make sure that the ‘path’ is set to the current directory. There are two kinds of M-Files:
Solve for five cycles, the response of an unforced system given by the equation: m x+ c x+ kx = 0 (1) For ξ = 0.1; m = 1 kg; k = 100 N/m; x (0) = 0.02m; x (0) = 0;
Let x = v (2) From the above expression we see that m+ cv + kx = 0 so the equation (1) reduces to )v – ( (3) We can see that the second order differential equation (1) has been reduced to two first order differential equations (2) and (3).
For our convenience, put x = y (1); = v = y(2); Equations (2) and (3) reduce to (1) = y (2); (4) (2) = [(-c/m)y (2) – (k/m)y (1)]; (5)
Using the values of ‘m’ and ‘k’, calculate the different values of ‘c’ corresponding to each value of ξ. Once the values of ‘c’ are known, equations (4) and (5) can be solved using MATLAB. The problem should be solved for five cycles. In order to find the time interval, we first need to determine the damped period of the system
Open a new M-file and write down the above two lines. The first line of the function file must start with the word “function” and the file must be saved corresponding to the function call; i.e., in this case, the file is saved as unforced1.m. The derivatives are stored in the form of a vector. This example problem has been solved for ξ = 0.1. We need to find the value of ‘c/m’ and ‘k/m’ so that the values can be substituted in equation (8). Substituting the values of ξ and ωn in equations (6) and (7) the values of ‘c/m’ and ‘k/m’ can be found out. After finding the values, substitute them into equation (8).
Now we need to write a code, which calls the above function and solves the differential equation and plots the required result. First open another M- file and type the following code. tspan=[0 4]; y0=[0.02;0]; [t,y]=ode45('unforced1',tspan,y0); plot(t,y(:,1)); grid on xlabel(‘time’) ylabel(‘Displacement’) title(‘Displacement Vs Time’) hold on;
This tells MATLAB that the vector ‘tspan’ is from 0 to 4 with a step size of 0.001. This example uses some arbitrary step size. If the step size is too small, the plot obtained will not be a smooth curve. So it is always better to use relatively larger step size. But it also takes longer to simulate programs with larger step size. So you have to decide which is the best step size you can use for a given problem. In order to solve for different values of ξ, calculate the values of ‘c/m’ for each value of ξ. Substitute each value of ξ in the function file, which has the derivatives, save the file and then run the main program to view the result. This process might be too tedious. The code can be made more efficient by incorporating a ‘For loop’ for the various values of zeta.
In the above code ‘y(:,1) represents the displacement ‘x’. To plot the velocity, change the variable in the plot command line to ‘y(:,2)’. The plot is attached below :