{include: ANSYS Google Analytics} {include: Spring-Mass System - Panel} \\ {note} If you get a "LaTex markup" error on this page, please reload the page to see the equations that use the Latex markup. {note} \\ *If you have never used MATLAB before, we recommend watching some of [these videos from The MathWorks |http://www.mathworks.com/products/matlab/videos.html], in particular the [Getting Started video. |http://www.mathworks.com/videos/getting-started-with-matlab-68985.html]. You can go through the videos either before or after completing this tutorial.* h1. Spring-Mass Harmonic Oscillator in MATLAB Consider a spring-mass system shown in the figure below. \\ \\ [!spring_mass.png|width=350!|^spring_mass.png]\\ \\ Applying _F = ma_ in the x-direction, we get the following differential equation for the location x(t) of the center of the mass: {latex} \[ m \ddot{x} + k x =0 \] {latex} The initial conditions at _t=0_ are {latex} \[ x(0)=1, \] {latex} and {latex} \[ v(0)=\dot{x} ̇(0)=0 \] {latex} The first condition above specifies the initial location _x(0)_ and the second condition, the initial velocity _v(0)_. \\ We'll solve this differential equation numerically, i.e. integrate it in time starting from the initial conditions at t=0, using MATLAB. We'll use Euler's method to perform the numerical integration. Some other topics covered in this tutorial are: * Making a plot of mass position vs. time and comparing it to the analytical solution * Separating out the Euler's method in a MATLAB "function" * Collecting multiple parameters in one box using "structures" In the process, you'll be exposed to the following handy MATLAB utilities: * Debugger to understand and step through code * Code analyzer to check code * Profiler to time code \\ [*Go to Step 1: Euler Integration*|SIMULATION:Spring-Mass System - Euler Integration] [Go to all MATLAB Learning Modules|SIMULATION:MATLAB Learning Modules] |