ode45, ode23,
ode113, ode15s, ode23s,
ode23t, ode23tb,
additional information
quadl use quad8 instead.function y = f1(x) global nf % declare nf as global variable y = x.*cos(x).^3; % must use ".*","./",".^" since x may be vector nf = nf + length(x); % update total number of function evaluations
Then you can use quad and find the number of function evaluations as follows:
global nf % declare nf as global (IMPORTANT!!)
nf = 0 % reset nf
q = quad('f1',0,1,.001) % or: q = adquad('f1',0,1,.001)
nf % show number of function evaluations
Note that you have to reset nf before each call of
quad.
adquad.m you
can evaluate func at a point x using
y=feval(func,x). Your m-file adquad.m should
look like this:
function q = adquad(func,a,b,tol) fa = feval(func,a); ... if ... q = ... else q = adquad(func,...) + adquad(func,...) end
Note this implementation is inefficient since it re-evaluates the
function at the same points several times. Once you've got
adquad working, rewrite it as follows: Use the following
adquad0.m
function q = adquad0(func,a,b,tol) fa = feval(func,a); fb = feval(func,b); q = adquad1(func,a,b,tol,fa,fb);
and write a function adquad1 which only uses
one new function evaluation fc=feval(func,c) at
the midpoint c. If the estimated error in
adquad1 is too large, it calls itself again for the two
subintervals, passing on the already computed function values in the
last two arguments.
finalval(a) instead of sol(a)
num2bin.m and
bin2num.m (note that you have to put
the files where Matlab can find
them)x the command s=num2bin(x)
gives a string of length 64 of zeros and ones with the machine
representation of x. For a string s of length 64
of ones and zeros the command x=bin2num(s) gives the
corresponding number x.s(1) contains the sign,
s(2:12) contains the exponent information,
s(13:64) contains digits
d2,...,d53 of the mantissa (for
normalized numbers).e is related to this by
e=bin2dec(s(2:12))-1022 or
s(2:12)=dec2bin(e+1022,11)x = 1, 0.1,
realmin, realmax, 0,
-0, Inf, -Inf, NaNhermite.m for Hermite interpolation,
example for Hermite, complete spline, not-a-knot
splineode45, ode23,
ode113, ode15s, ode23s,
ode23t, ode23tb , additional information
;'' at the end of lines to suppress the output
of uninteresting intermediate results (especially if these are large
arrays). Use the disp or fprintf commands to
clearly label all output, see
examples. Use the title, xlabel,
ylabel, legend commands to label your graphs, see example.print -dps figXY.ps in Matlab produces a postscript file
figXY.ps of the current figure which you can then send to the
printer.)