Sie sind auf Seite 1von 3

University of California, Irvine

Department of Civil and Environmental Engineering


Problem Solving with Matlab, Prof. B.F. Sanders
Quiz 2, Spring 2004, Sample

NAME: SCORE:

Instructions: Print your name. This quiz is to be administered in the computer lab,
with each student in front of a computer running Matlab. The problems will be solved
sequentially, and 2-10 minutes of time will allotted to each problem. After the period for
each problem expires, proctors will circulate through the room and evaluate whether the
problem was correctly answered. Two grading options exist for each problem: correct (1 pt),
and incorrect (0 pts). There will be no partial credit.
Problem # 1 ( ) [2 minutes]
Start Matlab, set the path to the “save files here/quiz2” directory on the desktop, and type
“pwd” followed by “ls” at the “EDU” command prompt.
Problem # 2 ( ) [7 minutes]
Write a script file that computes f(x) = x − x3 /3! + x5 /5! for a vector 0 ≤ x ≤ 2π consisting
of 100 points. Given that f(x) is an approximation of sin(x), create a figure that plots the
absolute error Ea and the relative error Er versus x. Use the “subplot” command to plot Ea
on the left side of the figure and Er on the right side of the figure. Show both the script file
and the figure to the proctor.
Problem # 3 ( ) [10 minutes]
The sine function is given by,
N

f(x) = (−1)n+1 x2n−1 /(2n − 1)!
n=1

given that N → ∞. Write a script file that computes the minimum integer value of N
needed to ensure that the relative error of f(x) is less than 1×10−7 for x = π/4. Show the
script file and the value of N to the proctor.
CEE 20 - Problem Solving with Matlab Quiz 2, Sample, Page 2

Problem # 4 ( ) [5 minutes]
Write a matlab script that creates a figure which graphically illustrates all roots of the
following function on the interval −10 ≤ x ≤ 10.
  x
1 1 9
f(x) = (x − 2)3 − x2 + 4 (1)
3 2 10

Scale the y-axes to range from -1 to 1 to clearly illustrate the roots. Show the figure to the
proctor.
Problem # 5 ( ) [10 minutes]
Create a function file to compute f(x) as given in Problem 4. Next, write a script file that
calls the built-in “fzero” command to find all roots to f(x) as given in Problem 4. (Hint:
“fzero” can be called multiple times with different initial guesses to find all roots.) Show the
script file and the roots it computed to the proctor.
Problem # 6 ( ) [7 minutes]
Write a function file which computes the following function,
4
f(x) = −1 (2)
ex + e−x

and write a script file which calls the “fzero” command to find all roots to this function on
the interval −∞ < x < ∞. Show the script file and the roots it computed to the proctor.
Problem # 7 ( ) [5 minutes]
Find the solution to the following system of equations using the backslash operator:

3x1 + 2x2 − 3 = 0
−x1 + 4x2 + 9x3 − 10 = 0
−x2 + 2x3 + 5 = 0

Show the solution to the proctor.


Problem # 8 ( ) [5 minutes]
Compute the rank of the following system to show that it is inconsistent by comparing this
to the number of unknowns.

4x1 + 2x2 − 3 = 0
−x1 + 4x2 + 9x3 − 12 = 0
x1 + 2x2 + 3x3 − 5 = 0

Show your work in the command window for the proctor to see.
CEE 20 - Problem Solving with Matlab Quiz 2, Sample, Page 3

Problem # 9 ( ) [7 minutes]
For the system below, compute the rank of the matrix A and the augmented matrix [A b].
If the system is consistent and a unique solution exists, compute the solution x. Otherwise,
do not attempt to compute a solution.

4x1 + 2x2 − 3 = 0
−x1 + 4x2 + 9x3 − 12 = 0
x1 + 2x2 + 3x3 − 5 = 0
−2x1 + 3x2 = 0

Show your work to the proctor.


Problem # 10 ( ) [10 minutes]
For the following nonlinear system of equations, write a function file which computes the
Jacobian matrix J given x. Call the function from the command window to compute J for
the case where x1 =0 and x2=0.

x21 − 4x1 x2 + 2x22 − 3 = 0


−2x1 + 3x22 = 0

Show the proctor the Jacobian matrix in the command window.

Das könnte Ihnen auch gefallen