Introduction to Computational Science and Engineering
CS 1115

Fall 2012
Solutions to
CS1112 Final Exam
Spring 2009
For Review Only.
Do Not Remove From Distribution Room.
Do Not Copy.
1
1. Boolean, characters and strings (20 points)
(a) Fill in the appropriate boolean condition to keep prompting the user until a number that is
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
9. The Discrete
vs
The Continuous
Finite Arithmetic
More practice with iteration and conditionals.
Screen Granularity
1
0.8
After how
many halvings
will the
disks
disappear?
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
0
0.5
1
1.5
2
Xenos Paradox
A wall is two feet a
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1112 Fall 2008 Prelim 1 Solutions
Question 1: (10 points)
Part (a): (3 points) What are the final values of variables x and y? x= y= x= y= 4; 8; y; x; x
8 8
y
Part (b): (3 points) What are the final values of variables x and y? x= 4; y= 8; if x<5 x= 1;
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS100M Fall 2007 Prelim 2
Oct 16 7:309:00pm
CIS121 Final Exam
Q1: (30) _ _
Name: _
(Legibly print last name, first name, middle name)
Q2: (20) _ _
NetID: _
Q3: (25) _ _
Statement of integrity:
I did not, and will not, violate the rules of academic integri
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
Spring 2009 Prelim 1 Solutions
Question 1: (20 points)
Part (a): (12 points)
Suppose the following fragment has been executed: % The first interval [a1,b1] has these endpoints: a1 = rand(1); b1 = a1+rand(1); % The second interval [a2,b2] has these endpoin
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1115 Lab 1 (August 29, 2013)
Completing the lab is very important, but your work is not graded and it is not submitted. If you nish before
the hour is over, then you can leave early or you can work on the Finished Early problems. If you do not
nish the
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1112 (CIS 1121) Fall 2008
Prelim 1
Sept 25 7:309:00pm
Q1: (10) _ _
Name: _
(Legibly print last name, first name, middle name)
Q2: (20) _ _
NetID: _
Q3: (20) _ _
Statement of integrity:
I did not, and will not, violate the rules of academic integrity
on
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1115 Lab 2 (Sept 5, 2013)
Completing the lab is very important, but your work is not graded and it is not submitted. If you nish before
the hour is over, then you can leave early or you can work on the Finished Early problems. If you do not
nish the pro
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1115 Lab 4 (September 19, 2013)
Completing the lab is very important, but your work is not graded and it is not submitted. If you nish before
the hour is over, then you can leave early or you can work on the Finished Early problems. If you do not
nish t
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1115 Lab 5 (September 26, 2013)
Completing the lab is very important, but your work is not graded and it is not submitted. If you nish before
the hour is over, then you can leave early or you can work on the Finished Early problem. If you do not nish
th
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
L8. Iteration and Graphics
Introduce Matlab Graphics
More practice with iteration and
booleantype thinking
Warmup for functions and arrays.
We will Draw Pictures
Using Three UserDefined*
Graphics Functions
DrawRect
DrawDisk
DrawStar
Rectangles
Circles
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS100M Lecture 1 January 25, 2005
Lec 1. Course Overview
Intuition
Programming
Computerbased problem solving
Theory vs Practice
0ther Perspectives
The Vehicle
is the Matlab Environment where you
can easily
Develop programs.
Display results & ideas graphi
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
What We Cannot Do
L3. Introduction to
Conditionals
We cannot make a computation contingent
upon other things.
Boolean expressions
The IfElse Construct
And, or, not
If the value of the arithmetic expression
Dice1 + Dice2 is seven, then increase
the value
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
Approach
L2. Basics
Variables and Expressions
Assignment Statements
BuiltIn Functions
Scripts
Comments
Keyboard Input
Formatting Output
Preview key concepts by first playing
with Matlab as a calculator.
From formula to program.
Three Formulas
A = 4r 2
co
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
L4. Iteration with forloops
The idea of Repetition
The forloop construct
A Geometric Restatement
Given a positive number A, find a
square whose area is A.
Motivating Problem:
Computing Square Roots
Given a positive number A, find its
square root.
An Ini
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS1112 Summer 2010
Final Exam Solutions
Print Name:
Problem 1 20 pts 16.5
Problem 2 15 pts 12.1
Problem 3 10 pts
5.7
Problem 4 10 pts
8.5
Problem 5 15 pts 10.5
Problem 6 10 pts
Problem 7 20 pts 14.8
Median = 81
Mean = 74
6.1
Problem 1(a). (10 points) What
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
Solutions to
CS1112 Final Exam
Fall 2008
For Review Only.
Do Not Remove From Distribution Room.
Do Not Copy.
1
1. Boolean (15 points)
Fill in the appropriate boolean condition for each problem below.
(a)
a= rand(1);
if
b= rand(1);
c= rand(1);
_
disp(The 3
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
L6. More on Iteration
Using a Count Variable
Developing ForLoop Solutions
Nested Loops
A YearPrinting Fragment
First = input(Enter first year);
Last = input(Enter last year);
for y = First:Last
fprintf(%5d\n,y)
end
How It Works
for y = First:Last
fprint
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
L5. More on Conditionals
Recall the ifelse Template
if
boolean expression
Commands to execute if the
Nested ifs
expression if TRUE
Multiple Alternatives
else
Commands to execute if the
expression if FALSE
end
A WarmUp Question
Variables a, b, and c have
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS1112 Summer 2010
Quiz 4
Print Name:
Problem 1 10 pts
Problem 2 10 pts
Problem 3 10 pts
1. (a) What is the output when the following script is executed? Show work.
A = zeros(100,100);
for i=1:100
for j=1:100
A(i,j) = 2*i+j;
end
end
fprintf(%10.1f\n,A(100
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS1112 Summer 2010
Quiz 4 Solutions
1. (a) What is the output when the following script is executed? Show work.
A = zeros(100,100);
for i=1:100
for j=1:100
A(i,j) = 2*i+j;
end
end
fprintf(%10.1f\n,A(100,1)
for i=1:100
for j=1:100
A(i,j) = A(j,i);
end
end
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS1112 Summer 2010
Quiz 5 (Solutions)
1. (a) Describe in English what the following script displays. Assume that ClockTower.jpg
represents a color image and is in the current working directory.
A = imread(ClockTower.jpg);
B = rgb2gray(A);
[m,n] = size(B);
Introduction to Computational Science and Engineering
CS 1115

Fall 2012
CS1112 Summer 2010
Quiz 5
Print Name:
Problem 1 10 pts
Problem 2 10 pts
Problem 3 10 pts
1. (a) Describe in English what the following script displays. Assume that CornellSnow.jpg
represents a color image and is in the current working directory.
A = imrea
Introduction to Computational Science and Engineering
CS 1115

Fall 2013
CS1115 Lab 6 (October 3, 2013)
Completing the lab is very important, but your work is not graded and it is not submitted. If you nish before
the hour is over, then you can leave early or you can work on the Finished Early problems. If you do not
nish the