Matlab Manual
Matlab Manual
Manual
Contents
1 Information for Instructors 1
1.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 Student Accessibility to MATLAB . . . . . . . 2
1.1.2 Working in a MATLAB Environment . . . . . 3
3 Integration 14
3.1 A De1nite Integral . . . . . . . . . . . . . . . . . . . . . 14
3.2 Integration by Parts; An Inde1nite Integral . . . . . 15
3.3 Approximation of Integrals . . . . . . . . . . . . . . . . 16
3.3.1 Trapezoidal Rule . . . . . . . . . . . . . . . . . . 16
3.3.2 Taylor Series . . . . . . . . . . . . . . . . . . . . . 16
solved with the use of a computer algebra system (CAS) such as MAT-
LAB. In addition, each chapter of the text contains at least one student
project. These projects are designed to give students substantial experience
in solving multistep problems, usually with the aid of a graphical calculator
or a CAS. The purpose of this manual is to provide a brief introduction to
the MATLAB computing environment, speci1cally geared to the textbook.
If you are considering having students use MATLAB for some of the
Technology exercises or Student Projects, please spend a few minutes read-
ing this section. It contains general advice and suggestions for the successful
implementation of MATLAB in your course.
spend some time in the lab. Learn any special access procedures and how
to launch MATLAB. Check to see if you can access materials in a course
archive or on the WWW, save a workspace 1le, exit MATLAB, transfer a
1le via e-mail or onto a diskette, and log out of the computer.
Command Function
syms Short cut for constructing symbolic objects
ezplot Easy-to-use function plotter
limit Limit of a symbolic expression
solve Symbolic solution of functional equations
double Convert symbolic expression to numerical
plot Linear plot
linspace Linearly spaced vector
subs Symbolic substitution
diff Differentiate
int Integrate
pretty Pretty print a symbolic expression
taylor Taylor series
polar Plot in polar coordinates
trapz Trapezoidal integration
Calculus , J & M
, MATLAB M
5
>> syms x y y1 y2
>> x = linspace(0, 2 pi);
>> y = sin(x);
>> y1 = sin(y);
>> y2 = sin(y1);
>> plot(x, y)
Calculus , J & M
, MATLAB M
6
>> syms x y
>> y = 2ˆx;
>> ezplot(y, [1 5])
>>
>> syms h
>> limit(sin(h)/h)
ans =
1
>> syms x
>> limit(tan(x), pi/2)
Calculus , J & M
, MATLAB M
9
ans =
NaN
>>help NaN
NaN Not-a-Number.
NaN is the IEEE arithmetic representation for Not-a-Number.
A NaN is obtained as a result of mathematically undefined
operations like 0.0/0.0 and inf-inf.
>> syms v c
>> limit(sqrt(1 (v/c)ˆ2), v, c, left )
ans =
0
ans =
Calculus , J & M
, MATLAB M
10
-sin(x)
>>syms h b
>>limit((b^h-1)/h,h,0)
ans =
log(b)
>> % The log is the natural logarithm ln.
x=
>> double(x)
ans =
1.1000
43.5593
0.6972 + 0.8014i
0.0850 + 0.9890i
0.7007 + 0.6283i
0.9231
0.7007 0.6283i
0.0850 0.9890i
0.6972 0.8014i
Only the positive real values of x are of interest to us. Thus for 0 < x <
1.1, x8 < 2x , while for 1.1 < x < 43.56, 2x < x8 , but for x > 43.56, 2x > x8 .
>>solve( x^4-5*x^3+21*x^2+13*x+49=0 );
Calculus , J & M
, MATLAB M
13
>>double(ans)
ans =
2.9956- 4.0003i
2.9956+ 4.0003i
-0.4956+ 1.3101i
-0.4956- 1.3101i
A =
1/2*(pi^r)^2-r^2*asin(1-h/r)-(r-h)*(h*(2*r-h))^(1/2)
>>Ah=diff(A,h)
Ah=
r/(1-(1-h/r)^2)^(1/2)+(h*(2*r-h))^(1/2)
-1/2*(r-h)/(h*(2*r-h))^(1/2)*(2*r-2*h)
>>Ah1=subs(Ah,r,1.5)
Ah1=
3/2/(1-(1-2/3*h)^2)^(1/2)+(h*(3-h))^(1/2)
-1/2*(3/2-h)/(h*(3-h))^(1/2)*(3-2*h)
>>Ah2=subs(Ah1,h,2)
Ah2 =
3/16*8^(1/2)*9^(1/2)+7/8*2^(1/2)
>>hrate=0.5/(6*Ah2)
Calculus , J & M
, MATLAB M
14
hrate =
1/2/(9/8*8^(1/2)*9^(1/2)+21/4*2^(1/2))
>>double(hrate)
ans =
0.0295
>>
3 Integration
ans =
[ -2.4356475028411506249717241735830]
[ 2.4356475028411506249717241735830]
A =
-1037004934973087065929065648105004366319763483/133804471
191183738849214309635890169035882496+4113442940027205/31691
Calculus , J & M
, MATLAB M
15
2650057057350374175801344*354506281325390153376730559031
^(1/2)+16*asin(1371147646675735/2251799813685248)
>>double(A)
ans =
10.4530
>> % The remaining area, and the mass, are given in the following
calculations.
>>Ar=16*pi-10.4530
Ar =
39.8125
>>M=Ar*0.5*8920*1e-6
M =
0.17756
>>
A =
65*exp(t)+10/(1+1/144*pi^2)*exp(t)*cos(1/12*pi*t)
+5/6*pi/(1+1/144*pi^2)*exp(t)*sin(1/12*pi*t)
-5/(1+1/36*pi^2)*exp(t)*cos(1/6*pi*t)
-5/6*pi/(1+1/36*pi^2)*exp(t)*sin(1/6*pi*t)
+5/4*pi/(1+1/144*pi^2)*exp(t)*cos(1/12*pi*t)
-15/(1+1/144*pi^2)*exp(t)*sin(1/12*pi*t)
>>
>>% The answer is easier to read if we pretty it up.
>>pretty(A)
exp(t) cos(1/12 pi t) pi exp(t) sin(1/12 pi t)
--------------------- -----------------------
65 exp(t) + 10 + 5/6
2 2
1 + 1/144 pi 1 + 1/144 pi
Calculus , J & M
, MATLAB M
16
f =
x^2-1/6*x^6+1/120*x^10-1/5040*x^14
>>I=int(f,x,0,pi/2)
I =
1/24*pi^3-1/5376*pi^7+1/2703360*pi^11-1/2477260800*pi^15
>>double(I)
ans =
0.8274