INTRODUCTION TO FOR AND WHILE LOOPS IN MATLAB
For loops and while loops allow the computer to run through a series of commands, repeatedly. In the case
of a for loop, the commands are executed a fixed number of times, whereas in a while loop the commands

Engineering Analysis 1 - Quiz 1
Name and Section: _Solution_
Answer the questions in the spaces provided on the question sheets.
Problem 1 (12 points)
Suppose that you try running each of the following five m-files in a MATLAB workspace that
has no previo

Visualize
a1 x + b1 y = c1
a2 x + b2 y = c2
Three dimension:
Each equation ax + by + cz = d corresponds to a hyperplane!
The solution of a linear system is the intersection of these
hyperplanes.
How about in higher dimensions?
Can we still visualize in hi

1
Practicing Exercises
Translate the following sentences into statements involving the reduced echelon form of a corresponding
matrix.
1. b is in the Span of cfw_a1 , ., an
2. The Span of cfw_a1 , ., an covers Rn , here all the vectors ai Rn .
3. The Sp

Example: Discount Pricing.
If buy less than 10 units, the price is 5 per unit, if 10 or more but
less than 20, the price is 3, otherwise the price is 2.
1. Enter from keyboard the number of items.
2. Output the unit price, and total money.
Today
Logical/

Summary of Matlab so far
Linear systems and matrix form
Input/Output
disp, fprintf
input
save, load
plot
Subarray, submatrix
a(x,y)
: ; begin:
end function
incremental:
end;
Operations with array and matrix
Built-in functions
max, min, size, length, sum,

Midterm
Paper-based test
Closed book: no computer, calculator, iphone, ipad, nexus7,
google glass.
Exam will be handed back on Tuesday, you have 24 hours for
regrading request.
Materials on exam
Matrix, vector, and their operations
How to write linear sys

An example
Data of a certain stock exchange is stored in a le.
Each column corresponds to a date; the rst row stores the prices,
the second row stores the quantities.
1.8
1
2 3
30 20 45 50
1. The le can be big, can Matlab read this le?
2. Enter from keybo

How to write a program
Given a numerical array a. Write a program to nd its largest
elements and the corresponding position.
a = a1 a1 a2 a3 . an
How to write a program
Given a numerical array a. Write a program to nd its largest
elements and the correspo

Example
Compute sum(z):
sum_z=0;
for ii=1:length(z)
sum_z=sum_z+z(ii);
end
More examples of for loop
Without generating random arrays x, y,z as in HW2, approximate
.
N=input(enter value of N: );
M=0;
for ii=1:N
x=rand();
y=rand();%create random scalars x,

Last week:
input/output
Subarray, submatrix (a:b; a:b:c; a(:,2)
Operation with arrays and matrices (+, -, *,/, .*, .+, ./, .)
Built-in (size, length,.)
This week:
Logic expressions
If command
For command
While command
Exercise
1. With for loop, compute:
1

HW due 2am Thursday!
My OFFICE HOURS:
L313 Tech building
Tuesday 3:30-5:00; Wednesday 1:00-2:30
TA OFFICE HOURS:
Tuesdays 5:00 to 8:00 pm and Wednesdays 4:00 to 8:00 pm
Where?
First class
PageRank: analyzing the structure of links among websites.
Let ri b

Yesterday
PageRank
Analyzing the structure of links among websites.
Idea: my ranking depends on the ranking of pages linking to me!
Yesterday
PageRank
Analyzing the structure of links among websites.
Idea: my ranking depends on the ranking of pages linkin

5. Digital audio
Audio signals, sampling, and reconstruction. One can think of an audio signal as a function p(t) representing the variation of air pressure p
versus time t. In digital audio systems, audio signals are sampled to produce sequences of numbe

4. Fitting models to data
By now you have seen a variety of examples in which the answer to some
problem is given by the solution to a system of linear equations. In each case
we relied upon the fact that a certain system of equations did have a solution

Engineering Analysis I
Case study
Google PageRank
Abstract
This case study serves to introduce the basic problem of linear algebra, a system of linear
equations. We discuss how one can solve such a system in MATLAB using either direct or
iterative methods