Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
MATLAB Google Analytics
MATLAB Google Analytics
Include Page
Spring-Mass System - Panel
Spring-Mass System - Panel

Step 1: Euler Integration

We start by specifying constants such as the spring mass m and spring constant k as shown in the following video.

HTML
 <iframe width="600" height="338" src="//www.youtube.com/embed/uXURYBVEv-c?rel=0" frameborder="0" allowfullscreen></iframe> 


We next specify the initial conditions and run the code that we have so far as shown in the video below. While running the code, we use the debugger to step through statements to understand what they do.

HTML
 <iframe width="600" height="338" src="//www.youtube.com/embed/IyRJmOd48NE?rel=0" frameborder="0" allowfullscreen></iframe> </iframe>


We have seen students write up huge chunks of code at one go that produces some obscure error. Students find that no amount of cursing and swearing at the computer fixes the error. To avoid this trap, we will build our code incrementally, testing at each stage. We first implement the Euler's integration method for one time-step as shown below and then will extend it to multiple time-steps.

HTML
 <iframe width="600" height="338" src="//www.youtube.com/embed/3khcp_ZjnaU?rel=0" frameborder="0" allowfullscreen></iframe> 


We move on to extend our code, or script in MATLAB lingo, to perform the Euler integration over multiple time-steps by looping over the appropriate statements.

HTML
 <iframe width="600" height="338" src="//www.youtube.com/embed/OaGJsamM8rw?rel=0" frameborder="0" allowfullscreen></iframe> 


Our script saves only the final location of the mass. We are also interested in saving the intermediate locations so that we can make a plot of position vs. time. We do this by creating arrays for the position and time.

HTML
<iframe width="600" height="338" src="//www.youtube.com/embed/8g4kSDT8SZo?rel=0" frameborder="0" allowfullscreen></iframe>



Go to Step 2: Array Pre-Allocation

Go to all MATLAB Learning Modules