Chapter 11. Troubleshooting
214
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.2
0.4
0.6
0.8
1
Figure 11.5. A First Attempt at Shading the Region between x2 and
x.
Its not too hard to gure out why our regions arent shaded; thats because we used
plot (which p
Debugging Techniques
215
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.2
0.4
0.6
0.8
1
Figure 11.6. A Second Attempt at Shading the Region between x2 and
x.
6
5
4
3
2
1
0
1.5
1
0.5
0
0.5
1
1.5
Figure 11.7. A First Attempt at Shading the Region between x2 an
Debugging Techniques
217
denote xvals reversed, we correct our Mle to read:
function shadecurves(f, g, a, b)
%SHADECURVES Draws the region between two curves
%
SHADECURVES(f, g, a, b) takes strings or expressions f
%
and g, interprets them as functions,
Chapter 11. Troubleshooting
210
1.5
1
0.5
0
3
2
1
0
1
2
3
Figure 11.1. A Spurious Graph of y = x1/3 .
Figure 11.1 is not the graph of y = x1/3 on the interval 3 x 3. Actually, the
graph to the right of the origin looks correct, but to the left of the orig
212
Chapter 11. Troubleshooting
Plotting the wrong kind of object
Using uppercase instead of lowercase letters in MATLAB commands, or misspelling commands.
Debugging Techniques
Now that we have discussed the most common mistakes, its time to discuss how
The Most Common Mistakes
211
rectly when opened in a new session.
CAUSE :
Change in the sequence of evaluation, or failure to initialize variables.
SOLUTION :
Make sure to clear or initialize variables that are not inputs to the Mle.
EXAMPLE :
The proble
Chapter 11. Troubleshooting
208
> A = (0,1,2)
? A = (0,1,2)

Error: Incomplete or misformed expression or statement.
These examples are fairly straightforward to understand; in the rst case, X(1) was
intended, and in the second case, A = [0,1,2] was inte
Common Problems
CAUSE :
207
See Managing Variables and Online Help in Chapter 2
Inattention to precedence of arithmetic operations.
SOLUTION :
Use parentheses liberally and correctly when entering arithmetic or algebraic expressions.
EXAMPLE :
MATLAB, lik
Common Problems
209
SOLUTION :
When you encounter a syntax error, review your input line carefully for mistakes
in typing.
If the user, intending to compute 2 times 4, inadvertently switches the symbols,
the result is
EXAMPLE :
> 2  * 4
? 2  * 4

Error
204
Practice Set C. Developing Your MATLAB Skills
in either Windows or UNIX, but at least make it work with your own operating
system.
15. Consider a sequence of complex numbers generated from a starting value z0
2
by the rule zn+1 = zn 0.75. For some val
Chapter 11. Troubleshooting
216
Figure 11.8. The Editor/Debugger.
0.9000
0.3000
0.3000
0.9000
1.5000
0.6561
0.0081
0.0081
0.6561
5.0625
If we now type
K> dbcont
we see in the gure window what is shown in Figure 11.9 below.
6
5
4
3
2
1
0
1.5
1
0.5
0
0.5
Solutions to the Practice Sets
Solutions to Practice Set A: Algebra and Arithmetic
1.
(a)
1111  345
ans =
766
(b)
format long; [exp(14), 382801*pi]
ans =
1.0e+06 *
1.20260428416478
1.20260480938683
The second number is bigger.
(c)
[2709/1024; 10583/4000;
Equilibrium
Multiple Choice
Identify the choice that best completes the statement or answers the question.
_
_
_
_
1. Which of the statements concerning equilibrium is false?
a. A system that is disturbed from an equilibrium condition responds in a manner
MAPA INSTITUTE OF TECHNOLOGY
SCHOOL OF CHEMICAL ENGINEERING AND CHEMISTRY (INTRAMUROS)
VISION
Mapa shall be among the best universities in the world.
MISSION
a. The Institute shall provide a learning environment in order for its students to acquire the
at
Michael Angelo Riano Arce
2856 Oroquieta St Sta Cruz Manila
Michael Angelo Riano [email protected]
09392288598
Objective:
Seeking a position in your company that I can utilize my potential that will give opportunities to
enhance my personality and career for
Joshua R. Arce
2856 Oroquieta St. Sta. Cruz, Manila
09982837524
[email protected]
Objective
To be involved in work where I can utilize skill
and creatively involve with system that effectively
contributes to the growth of organization.
Personal Infor
Areej Gabrielle Rollon
September 01, 2015
HUM13BR10
Prof. Clarisse Virgino
Movie Review: One More Chance
One More Chance is a movie starring Bea Alonzo (Basha) and John Lloyd Cruz (Popoy). This
movie was released last November 14, 2007 directed by Miss C
Solutions to Practice Set A: Algebra and Arithmetic
223
better =
cos(2*x)
how =
combine(trig)
7.
3301
pretty(sym(3)301)
ans =
4.1067e+143
4106744371757651279739780821462649478993910868760123094144405702351069915\
324972297814006184670668241647514533217939
Solutions to Practice Set A: Algebra and Arithmetic
221
z =
91/92
Now well check the answer.
A = [3, 4, 5; 2, 3, 7; 1, 6, 1]; A*[x; y; z]
ans =
2
1
3
It works!
4.
[x, y, z] = solve(3*x  9*y + 8*z = 2, .
2*x  3*y + 7*z = 1, x  6*y + z = 3, .
x, y,
Solutions to the Practice Sets
220
2.
(a)
cosh(0.1)
ans =
1.00500416805580
(b)
log(2)
ans =
0.69314718055995
(c)
atan(1/2)
ans =
0.46364760900081
format short
3.
[x, y, z] = solve(3*x + 4*y + 5*z = 2, .
2*x  3*y + 7*z = 1, x  6*y + z = 3, .
x, y, z)
x
Chapter 11. Troubleshooting
206
EXAMPLE :
Suppose that you set up a loop like
> for i = 1:10
.
end
and later in your session you enter the complex number 2+i; then in fact you have
entered the number 12, because at the end of the loop the variable i is se
Chapter 11
Troubleshooting
In this chapter, we offer advice for dealing with some common problems that you
may encounter. We also list and describe the most common mistakes that MATLAB
users make. Finally, we offer some simple but useful techniques for de
A Model of Trafc Flow
189
In1 Out1
car speeds
Reactiontime
Delay
1
xo s
C
Integrate
u" to get u
initial velocities
0.8
sensitivity
parameter
Subsystem:
computes velocity
differences
1
xo s
relative
car positions
Integrate
u to get u
Ramp
C
initial car pos
Chapter 10. Applications
188
of z exp(z) for z = T = iy a complex number on the critical line Re z = 0, and
comparing with plots of T (ei 1) for various values of the parameter T .
syms y; expand(i*y*(cos(y) + i*sin(y)
ans =
i*y*cos(y)y*sin(y)
ezplot(y*
A Model of Trafc Flow
185
% A surface plot is often a good way to study a solution.
surf(x, t, u)
title(Numerical solution computed with 21 mesh points in x)
xlabel(x), ylabel(t), zlabel(u)
% function [c, f, s] = pdex(x, t, u, DuDx)
c = 1;
f = (1 + (x/5)