Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
clc
clear all
close all
res=10;
x=linspace(1,1,res);
y=linspace(0,2,res);
%create meshgrid
[X ,Y]=meshgrid(x,y);
%calucalte potential
pot=X.^2Y.^2;
%calculate stream function
stream=2*X.*Y;
c1=contour(X,Y,pot,9);
clabel(c1);
axis equal;
hold on
%plot st
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 18
More on Interpolation Methods
Interpolation from data on an irregular
(nonrectangular) grid.
2
1
Application: Table Lookup
Partial pressure in kPa
5
10
20
temp in C
0.067
0.
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 5
TOPICS and READING ASSIGNMENTS:
The switchcase structure
Save and load variables (Chapter 13).
(Useful stuff )
Function Mfiles (Chap. 12).
Function handles
Inline function
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 13
Optimization and solving nonlinear
equations (Chapter 22).
Focus on fzero and fminbnd for
onedimensional (single variable
problems)
and fminsearch for multidimensional
pro
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Code for Rooms 182 and 184
113751
We have a site on Coursework
https:/coursework.stanford.edu/portal/
2
1
Lecture 2: Matlab in Action!
Chapters 24 and bits and pieces from other
chapters
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 6
Function handles
Inline functions
More on defining and using functions
Inclass exercise
Organizing a small project
Review Chapter 9. Using eval (9.3)
For self study: Using ASCII
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 19
On solving initial value problems (IVPs),
or ordinary differential equations
(ODEs).
Matlabs numerical methods for solving
IVPs.
See Chapter 24.
2
1
Very important topic
beca
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Outline
Class Logistics
Class Objectives
2
1
Instructor:
Peter K. Kitanidis
Room 147 in Y2E2
tel.: (650) 7238321
Email: [email protected]
Office Hours:
Tentative TuFri 35, starting
S
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 4
Logical Operators
Control the flow of calculations (Chapter
11). (A critical part of programming. It
takes minutes to learn, but a bit longer
to master )
2
1
Logical Operators
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 3
Arrays (Chapter 5). A primer.
The Basic Relational and Logical Operators
(Chapter 10).
2
1
Matrices are
rectangular arrangements of numbers.
Each number belongs to a row and
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 9
Plotting surfaces through contour and
gridded surface functions
Plaid grids
Special grids
2
1
meshing and contouring
z ln
x2 y 2 1
>x = 0:2:10; y = x; %axes
>[X, Y] = meshgrid
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 15
More on Differentiation and Integration
(Chapter 23).
2
1
triplequad numerically evaluates
integral in 3 dimensions
Limitation: dblquad and triplequad
work for rectangular do
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 8
Workspace of functions, local and nested
functions
Remarks on good programs and
programming style.
3D plotting (Chapter 26). Creating and using
a mesh to plot a surface throu
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 10
Special grids to plot cylinders, sheres,
ellipsoids, etc.
Improving the quality of figures
Publication quality
2
1
Some special grids
>%Special grids with commands:
>%cylinde
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
clc
close all
clear all
0efine constants
g = 9.81;
l=0.2485;
0efine initial conditions for 3 different cases
y01=[pi/4,0];
y02=[pi/18,0];
y03=[pi/180,0];
tspan=[0 3];
0efine odes in two equations by splitting main equation
%x(1) is theta and
%x(1)'=x(2)
f
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
clc
clear all
close all
t=50;
%call function
[a,b]=tracer(t);
%plot points in blue color
plot(a,b,'.b');
xlabel('x');
ylabel('y');
%calculate mean of locations. 2 means required to translate matrix into
calar
Xmean=mean(mean(a);
Ymean=mean(mean(b);
%get v
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Announcement
No class on Tuesday (tomorrow)
Exam will be post around 10AM on
Tue., due at 10AM on Wed.
2
1
Lecture 16
More on Differentiation and Integration
(Chapter 23).
3
Advanced To
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 17
Interpolation Methods (Chapter 18).
Onedimensional interpolation;
Twodimensional interpolation from data on
a rectangular grid;
Interpolation from data on an irregular
(no
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 14
Differentiation and Integration (Chapter 23).
To compute:
Rates of change and
Lengths, areas, and volumes.
We will focus on
diff computing differences;
trapz and cumtrapz,
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 11
More on Array Manipulation (Chapter 5
Please go through it!)
Matrix (or Linear) Algebra (Chapter
16)
2
1
Why matrices and linear algebra
They are used in, for example:
Mathe
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 20
More on solving ODEs.
Review and continuation of solving IVPs
in MATLAB.
Example: The spring vibration problem.
Formulation
and solution in MATLAB.
Solving higherorder ODE
Computations in Civil and Environmental Engineering
CEE 201D

Spring 2014
CEE101D/201D
Computations in Civil and
Environmental Engineering
1
Lecture 7
Organizing a small project
About the workspace of functions
Local functions versus nested functions
Remarks on good programs and
programming style.
2
1
Applications
Organizing a