# MATLAB-Fa14

CSE Training Workshops in MATLAB, Fall 2014 • MEL 1001, 10 am–Noon

Project maintained by uiuc-cse Hosted on GitHub Pages — Theme by mattgraham

All workshops will be held in 1001 Mechanical Engineering Laboratory, an EWS computer laboratory. There is no sign-up for this series—walk-ins are welcome and encouraged!

# Beginning Scientific Programming with MATLAB

### Sep. 4, 10–Noon • MEL 1001

This workshop targets students with little to no programming experience. We will conduct a hands-on walkthrough of what MATLAB has to offer as a foundation for later tutorials throughout the semester.

We will cover the following topics:

• Variables, functions, sequences, dictionaries
• Libraries and modules
• Loops, logic, and conditionals
• Input/output, files

(If you don't know what some of these mean, don't worry! This is a gentle introduction.)

# Introduction to MATLAB

### Oct. 9, 5–7 pm • MEL 1001

This workshop, offered multiple times, targets students with some prior programming experience in other languages but who are interested in learning MATLAB for research or coursework. We will conduct a hands-on walkthrough of what MATLAB has to offer as a foundation for later tutorials throughout the semester. (This workshop will overlap with much of the content in the "Beginning MATLAB" course above, so there's no need to attend both.)

We will cover the following topics (in more depth than the beginning class above):

• Libraries and modules
• Loops, logic, and conditionals
• Input/output, files
• Basic numerical examples & matrix solutions

### Lesson Materials

Basic Exercises

Skeleton code for computedamrateofflow.m.

Spring data:

m = [5 10 20 50 100];                 % mass data, g
d = [15.5 33.07 53.39 140.24 301.03]; % displacement, mm
g = 9.81;                             % g = 9.81 m/s^2
F = m/1000 *g;                        % spring force (N)


# Numerical Programming with MATLAB

### Oct. 9, 10–Noon • MEL 1001

This tutorial focuses on the solution of differential equations and similar systems with MATLAB.

Spring Interpolation Data

m = [5 10 20 50 100];                   %mass data (g)
d = [15.5 33.07 53.39 140.24 301.03];   %displacement data (mm)
g = 9.81;                               %g = 9.81
F = m/1000 *g;                          %compute spring force (N)


Heat Equation by Finite Difference Method

Finite-difference models are used throughout engineering to obtain numerical solutions to differential equations. This particular system models the heat equation

$$\frac{1}{\alpha} \frac{\partial u}{\partial t} = \frac{\partial^2 u}{\partial x^2}$$

given an initial condition of $u(x,t=0) = \sin\left(\pi x/L\right)$ and boundary conditions of $u(x=0,t) = 0$ and $u(x=L,t) = 0$.

To approximate a derivative, the most straightforward way is to take the formal definition

$$f'(x) = \frac{f(x+h)-f(x)}{h}$$

and use a small but nonzero step $h$ in your calculation.

Application of this principle to the heat equation leads to a statement of the form

$$\frac{1}{\alpha} \frac{u^m_i - u^{m-1}i}{\Delta t} = \frac{u^{m-1}{i-1} - 2 u^{m-1}{i} + u^{m-1}{i+1}}{\Delta x^2}$$

or $u^m_i = \frac{\alpha \Delta t}{\Delta x^2}u^{m-1}{i-1} + \left[1 - 2\left(\frac{\alpha \Delta t}{\Delta x^2}\right)\right]u^{m-1}{i} + \frac{\alpha \Delta t}{\Delta x^2}u^{m-1}_{i+1}$.

This clearly yields a way to calculate subsequent time steps point-by-point from the previous time step's data.

Radioactive Decay System of Differential Equations

# Image Processing in MATLAB

### Oct. 30, 10–Noon • MEL 1001

This workshop will introduce image data structures and elements of image analysis in MATLAB.

### Lesson Materials

Satellite k-means detection script

Bridge angle detection script

# About These Workshops

### Contributors

Neal Davis, Rishabh Narang, and Erika Fotsch developed these materials. This content is available under a Creative Commons Attribution 3.0 Unported License.

# Contact

If you have any questions about course availability, concepts, or content, please contact Neal Davis, Training Coördinator for Computational Science & Engineering, at davis68 at illinois dot edu.