1080 PDF ADDE


Addendum: MATLAB 6
When I started developing this book s material in 1997, the faculty and stu-
dents in the Electrical and Computer Engineering Department at the City
University of New York (CUNY), my home institution, were in the most envi-
able position of having access to up-to-date versions of MATLAB on all major
computer platforms at the university. Unfortunately, this state of bliss did not
last. MATLAB 6 releases are now available for the PC and UNIX"! platforms,
but not for the MAC"!. Faced with this situation and the significant number
of instructional laboratories equipped with MAC computers, both on CUNY
campuses and in feeder institutions, and the large number of students own-
ing MAC computers, I opted to use in this text the syntax that is still common
to all platforms, i.e., not the latest. Fortunately, this was still possible because
MATLAB 6, Release 12, still accepts the obsolete commands, although newer
versions of these commands are now recommended.
As there is no guarantee that this backwards compatibility will continue in
future releases, in this addendum, I summarize only those modifications that
are of direct relevance to this text. Further details can be found in the
MATLAB manuals and the help files.
1. The function handle was added.
a. A function handle is a MATLAB data type that contains infor-
mation used in referencing a function. The function handle
stores all the information MATLAB needs to evaluate the func-
tion from any location in the MATLAB environment.
b. The feval function can be used with either function handles
or function name strings. Evaluation of function handles is pre-
ferred over evaluation of the function name.
2. Most names in MATLAB are now truncated after the 31st character,
i.e., MATLAB cannot, for example, distinguish between two names
with the same first 31 characters.
3. The following MATLAB functions have been renamed:
Old name New Name Description
fmin fminbnd Minimize a function of one variable
0-8493-????-?/00/$0.00+$.50
© 2000 by CRC Press LLC
© 2001 by CRC Press LLC
Old name New Name Description
fmins fminsearch Minimize a function of several variables
quad8 quadl Evaluate one dimensional integral
4. The ODE problem components that were passed to the Solver
through an ODE file are now passed directly as arguments. The
Solver is one of the ODE solver functions such as ode23, ode45,
etc. &
NOTE The reader should not conclude from these limited syntax changes
that MATLAB 6 is only a cosmetic improvement over its previous version.
Nothing is further from the truth. In our most recent extensive nonlinear
optics computations, my colleague Irina Gladkova and I obtained, using
MATLAB 6, almost an order of magnitude improvement in execution time
and similar impressive improvements in memory management over previ-
ous versions performance.
In the following examples, we illustrate the use of some of the above:
Example Ad.1
Find the abscissa of the minimum of the function y = (x  2)2 + 3 over the inter-
val [0 4].
Solution:
a. Create a function M-file:
function y=ad1(x)
y=(x-2).^2+3;
b. Call from the command window:
xmin=fminbnd(@ad1,0,4)
Example Ad.2
2
Find the coordinates and the value of the minimum of the function y = 2x1 +
2
4x1x2 + 3x2 near the point (1, 1).
Solution:
a. Create a function M-file:
function y=ad2(x)
y=2*x(1)^2+4*x(1)*x(2)+3*x(2)^2;
b. Call from the command window:
© 2001 by CRC Press LLC
[xmin,ymin]=fminsearch(@ad2,[1,1])
Example Ad.3
Plot as a function of time the solution and its first derivative for the following
Van der Pole equation:
y2 2 - (1 - y2 )y2 + y = 0,
with the following initial conditions y(0) = 2 and y2 (0) = 0.
Solution:
a. Reduce the above second-order ordinary differential equation to
two first-order equations.
Let: y1 = y and y2 = y2 ,
The system of first order ODE is then:
y12 = y2
2
y2 = (1 - y1 )y2 - y1
2
b. Create a function M-file:
function yprime=vandpol(t,y)
yprime=[y(2);(1-y(1)^2)*y(2)-y(1)];
c. Enter in the command window:
tspan=[0 30];
yinit=[2;0];
[t,y]=ode45(@vandpol,tspan,yinit);
plot(t,y(:,1),t,y(:,2))
© 2001 by CRC Press LLC


Wyszukiwarka

Podobne podstrony:
1080 PDF?0
1080 PDF?7
1080 PDF?9
1080 PDF?3
1080 PDF APPX
1080 PDF SUPPL
1080 PDF?2
1080 PDF REF
1080 PDF?4
ATX 1080
1080 (2)
1080 PDF TOC
1080 1
1080 PDF?6
1080 PDF?8

więcej podobnych podstron