Engineering
College of San Mateo
ENGR215
L. Demsetz
More Programming
Comments:
When you write a function, be sure to include comments that explain the functions inputs (arguments) and
outputs (return values). Programmers often refer to requirements on the
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Name:
What is the most advanced math class you have completed?
What is the most advanced physics class you have completed?
Note: ENGR 215 does not have a physics prerequisite.
Intended major and transfe
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Sample Questions for Final Exam
The final exam is Thursday, December 13 in 19-124, 11:10 a.m. -1:40 p.m. for the on-campus section and
5:10 p.m. 7:40 p.m. for the on-line section. The exam is open book
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Solutions to Sample Questions for Final Exam
The final exam is Thursday, December 13 in 19-124, 11:10 a.m. -1:40 p.m. for the on-campus section and
5:10 p.m. 7:40 p.m. for the on-line section. The exam
Engineering
College of San Mateo
ENGR215
L. Demsetz
ENGR 215 Computational Methods for Engineers & Scientists
Fall 2012, 3 units
Section AX, CRN 91590, Lecture: TTh 11:10 12:00 in 19-103107, Lab: T Th 12:10 1:30 in 19-124
Section WX, CRN 91595, on-line; p
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Solutions to Sample Questions for Exam 2
Exam 2 will be Thursday, November 8 during lecture and lab for the on-campus section and 5:10 7:30
p.m. in 19-124 (overflow portion) for the on-line section. The
%Jeffrey Chu, ENGR215
function t = A3P4(h,vO,g)
% Computes the time of a dropped object.
% Given: h = vO*t - 1/2*g*t.^2
% Let's convert the equation to a polynomial instead:
% 1/2*g*t.^2 - VO*t + h = 0
% Putting the polynomial in an array using coefficie
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Sample Questions for Exam 2
Exam 2 will be Thursday, November 8 during lecture and lab for the on-campus section and 5:10 7:30
p.m. in 19-124 (overflow portion) for the on-line section. There will be a
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Solutions to Sample Questions for Exam 1
1. For the matrix A =
1
5
9
13
2
6
10
14
3
7
11
15
4
8
12
16
What will be displayed when the following MATLAB statements are executed (assume the statements
are
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Sample Questions for Exam 1
Exam 1 will be Thursday, October 4 during lecture and lab for the on-campus section and 5:10 7:30 p.m.
in 19-124 for the on-line section. There will be a pencil and paper por
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Numerical Integration and Differentiation in MATLAB
Chapter 7 introduces MATLABs numerical methods for calculus and differential equations.
These brief notes summarize numerical integration and differen
Engineering
College of San Mateo
ENGR215
L. Demsetz
Programming Examples Part 1
This material is intended to supplement, not replace, the assigned reading in the text.
These examples are designed to help you think about how to write a program or function.
Engineering
College of San Mateo
ENGR215
L. Demsetz
Programming Examples Part 2
This material is intended to supplement, not replace, the assigned reading in the text.
When you write a program, you often have to decide how to represent the information you
Engineering
College of San Mateo
ENGR215
L. Demsetz
Programming in MATLAB
This material is intended to supplement, not replace, the assigned reading in the text.
User defined functions
User-defined functions are script files (.m files) that contain as the
Engineering
College of San Mateo
ENGR215
L. Demsetz
Probability, Statistics, and Simulation
This material is intended to supplement, not replace, the assigned reading in the text.
Probability
Probability is the relative frequency of occurrence of an outco
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Simulation Project
Assigned:
Due:
October 18, 2012
Proposal November 10 (will be returned with comments by Nov. 14)
Code upload December 4
Final Report and Presentation December 6
This project should de
Engineering
College of San Mateo
ENGR 215
L. Demsetz
Recursion Examples
Below are two recursive functions and the output that they produce. Display statements have
been added to demonstrate the recursive calls.
function result = mymin(inArray)
%Recursive
Chapter 3 solutions for problems 13,14,16,17,19,23
3.13 The function file is
function cost = fence(R)
A = 2000;
L = (A-0.5*pi*R.^2)./(2*R);
cost = 40*(2*R+2*L)+50*pi*R;
The session is
optimum R = fminbnd(fence,0,100)
optimum R =
21.4270
min cost = fence(o
Chapter 4 solutions for problems 41,42,44,47,48
41. The script file is
W = input(Enter the weight: );
materials = input(Enter the materials: ,s);
switch materials
case metal on metal
F = .2*W
case wood on wood
F = 0.35*W
case metal on wood
F = 0.4*W
case
Chapter 4 solutions for problems 2,4,5,7,9,12,17,19
2. a) The pseudocode is:
1. Prompt the user to enter the coefficients. Be sure to specify the format and the order
in which they must be entered.
disp(Enter the three coefficients in brackets (Highest po
Chapter 4 solutions for problems 20,23,24,28,32-34
20. (a) The function file is
function package(W,k1,k2,d);
if W < k1*d
x = W/k1;
else
x = (W+2*k2*d)/(k1+2*k2);
end
disp(The distance traveled is:)
disp(x)
The session is
package(500,10000,15000,0.1)
The d
Chapter 5 solutions for problems 21,23-27
21. The M-file is:
Year = 2000:2004;
Temp = [21,18,19,20,17];
subplot(2,2,1)
stem(Year,Temp),xlabel(Year), ylabel(Temperature (Deg. C)
subplot(2,2,2)
bar(Year,Temp),xlabel(Year), ylabel(Temperature (Deg. C)
subplo
Chapter 5 solutions for problems 29,31,33,35,36
29. The following script file creates the plot. The start of the path is marked with an asterisk, and the end
is marked with a + sign.
t = 0:0.002:0.2;
x = (.5+5*t).*sin(2*pi/3)*t).*cos(4*pi*t);
y = (.5+5*t)
Chapter 6 solutions for problems 1-4,7,9
1. The session is
f = [0,0.94,2.3,3.28];
y = [4.7,7.2,10.6,12.9];
x = y-4.7;
p = polyfit(x,f,1)
p =
0.3998 -0.0294
Thus the least squares straight line is f = 0.3998x 0.0294, and the spring constant is
approximatel