Goals
Explore the Matlab windows
Use Matlab as an advanced calculator
Learn how to save and document your work
Matlab Environment
Command Window
The Command Window on the right is the main panel where you interact with MATLAB.
You type numbers and command
Creating Functions
User defined functions are created in a similar way as scripts. The difference between scripts and functions is that a
function typically uses data passed as arguments and returns a result. A script file is simply a collection of MATLAB
Linear Algebraic Equations
Linear versus nonlinear equation
A linear equation in two variables x, y
ax+b y=c
A nonlinear equation in two variables x, y
a x2 + b y = c
Solution of linear equations is covered in this lecture. Solution of nonlinear equations
Creating Functions without Separate M-files
The matlab functions for solving nonlinear equations require that the equations be defined as functions. The usual way
of defining functions in matlab requires the function to be saved as a separate M-file. For
Curve fitting
Describes techniques to fit curves (curve fitting) to discrete data to obtain intermediate estimates. Data exhibit a
significant degree of scatter. The strategy is to derive a single curve that represents the general trend of the data.
f x
x
Numerical Differentiation
Needed for
A complicated continuous function that is difficult or impossible to differentiate directly.
A tabulated function where values of x and f(x) are given at a number of discrete points, as is often the case
with experim
Numerical Integration
Needed for
complicated functions that are difficult or impossible to integrate directly.
A tabulated function where values of x and f(x) are given at a number of discrete points, as is often the case
with experimental or field data
Numerical Integration Using Gauss
Quadrature
Gauss Points and their Corresponding Weights
The locations of Gauss points and the appropriate weights are determined by requiring that the numerical integration
give exact integrals for constant, linear, quadr
Differential Equations
Equations which are composed of an unknown function and its derivatives are called differential equations. They play
a fundamental role in engineering because many physical phenomena are formulated mathematically in terms of
equatio
Background for numerical solution of odes
Consider a general first-order ode expressed as follows.
dy
dt
= f t , y ; y t0 = y 0
Here t is the independent variable and y is the solution or dependent variable. The right-hand side of the equation is
some gen
Stiff odes
Stiff ODEs - ODEs that have both fast and slow components to their solution. Stiff differential equation require
extremely small step size to achieve accurate results.
A stiff system is the one involving rapidly changing components together wit
Boundary-Value Problems
An nth order equation requires n conditions for a unique solution. If all conditions are specified at the same value of
the independent variable, then we have an initial-value problem. If the conditions are specified at different v
Optimization Problems
Reference: Bhatti, M.A. Practical Optimization Methods with Mathematica Applications, Springer 2000.
Finding minimum or maximum of a function, often in the presence of constraints.
Root finding and optimization are related, both invo
Some useful functions
sum & prod functions
B = sum(A) returns sums along different dimensions of an array. If A is a vector, sum(A) returns the sum of the
elements. If A is a matrix, sum(A) treats the columns of A as vectors, returning a row vector of the
Use of array operations
Array operations are useful for generating tables of values by evaluating a given function at specified values of the
independent variable.
Example
Evaluate the following function for x values indicated.
f x = x3 + 3 x2 + 1 for x f
Goals
Explore the Matlab windows
Use Matlab as an advanced calculator
Learn how to save and document your work
Matlab Environment
Command Window
The Command Window on the right is the main panel where you interact with MATLAB.
You type numbers and command
Interpolation
Estimation of intermediate values between precise data points. An nth order polynomial can be defined to interpolate
between n + 1 data points.
f x = a0 + a1 x + a2 x2 + + an xn
There is one nth-order polynomial that fits n + 1 points. Howev
Final Exam
Table of Contents
Problem
Problem
Problem
Problem
Problem
1
2
3
4
5
.
.
.
.
.
1
1
1
3
6
Problem 1
r = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0,]; V = [1.0, 0.96, 0.84, 0.64, 0.36, 0.0]; fQ = @(r) 2*pi.*r*V; quad(fQ, 0, 1)
Problem 2
Problem 3
data = xlsrea
Homework- Haochen, Zhang
Table of Contents
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
Problem
1.1
1.2
1.3
1.4
2.1
2.2
2.3
2.4
2.5
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
CE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Instructor: M. Asghar Bhatti
Homework 1
Problem 1
Use appropriate command(s) to create the fo
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
C&EE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Instructor: M. Asghar Bhatti
Homework 2
Problem 1
Given that x = [1 5 2 8 9 0 1] and y = [5
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
C&EE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Instructor: M. Asghar Bhatti
Homework 3
Problem 1
The displacement formulation of a truss r
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
C&EE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Instructor: M. Asghar Bhatti
Homework 4
Problem 1
The crank AB of length R = 90 mm is rotat
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
CEE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Examination 1
Instructor: M. Asghar Bhatti
Name _
Problem Max Points Points Scored
1
2
10
15
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
CEE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Examination 2
Instructor: M. Asghar Bhatti
Name _
Problem Max Points Points Scored
1
2
10
5
University of California, Los Angeles, CA
Department of Civil & Environmental Engineering
CEE 15 Introduction to Computing for Civil Engineers
Summer Session 2012
Final Examination
Instructor: M. Asghar Bhatti
Name _
Problem Max Points Points Scored
1
2
1
CEE15
Introduction to Computing for Civil Engineers
!
An Introduction to MATLAB (Version 4.61 Release 1;)
Chapter 1 Introduction to MATLAB
1.1. MATLAB Windows
Table 1.1 MATLAB Windows
Window
Purpose
"o$a&'!(i&'o*!
+ai&!*i&'o*,!e&ters!1aria2les,!ru&s!5ro6r
BVP Example
Given Second-Order BVP
y =
2x
2
y -
y + x2 + 1; 0 < x < 1
y0 = 2; y 1 = -1
x2 + 1
x2 + 1
Conversion to a first-order system
z1 = y ; z2 = y
z = z2
1
z =
2
2x
z2 -
2
z1 + x 2 + 1
z1 0 = 2; z2 1 = -1
x2 + 1
x2 + 1
Using shooting method
de = @(x