[X1,X2] = meshgrid(-8:.2:8,-10:.2:10); contour(X1,X2, sin(X1-X2) + X1.^3./20 ,[0 0],'b-'); hold on contour(X1,X2, cos(X1+X2) - X2.^2./20 ,[0 0],'r--'); hold off
Note that you MUST use .* ./ .^ instead of * / ^ for element-wise arithmetic operations with the arrays X1 and X2.
Problem 1:
1(b): You can get equidistant nodes using
x=linspace(-pi,pi,10) .
For
1(c): Use the bound for the Chebyshev polynomial
below.
Problem 2: Use [x,y] = pickpoints(9) to
enter the points. Download pickpoints.m
For (a) do the following:
t=1:9; te=1:.05:9;t, x use
spline to evaluate the interpolating function at points
te, yielding vector xet, y use
spline to evaluate the interpolating function at points
te, yielding vector yeplot(x,y,'o',xe,ye); axis equalFor (b) use polint instead of spline.
Problem 3: Remember to take the logarithms
(log in Matlab) of the population values before doing the least
squares fit: p=[75.995,...,249633]; q=log(p) .
Print out the vector c which you get for (i),(ii),(iii) and
check that they are the same (up to roundoff errors). Then use one of
those c vectors for the plot and for the predicted
population.
Problem 4: Download co2.dat , then use in Matlab load
co2.dat (not load co2 as stated in the
problem).
IMPORTANT:
Use x = 1:length(co2) since
x is the time in months (the seasonal variations in
(ii) have a period of 12 months.)
includes information about textbook, office hours, grading policy
num2bin.m
and bin2num.m (note that you
have to put the files where
Matlab can find them) x = A\b or[L1,U] = lu(A); % compute
factorization A=L1 U using Gaussian elimination with pivoting,
choosing pivot candidates with largest absolute valuey = L1\b; % "forward substitution"
x = U\y; % back susbstitution
condition = condestdec(L1,U) %
estimate condition number of A (for 1-norm)norm(x,1) ,
norm(x,2) , norm(x,inf) cond(A,1),
cond(A,2), cond(A,3) (in all cases
inv(A) is computed)condest(A)
(actually computes LU decomposition of A) condestdec(L1,U) condestdec.m ,
for Matlab 5 use condestdec5.m
instead)xj = (a+b)/2 + cos(Then(j-1/2)/n) (b-a)/2 for j = 1,...,n.
|(x-x1)...(x-xn)|2 ((b-a)/4)n for x in [a,b]
x contains the x-coordinates of the nodes, the column
vector y contains the function values at the nodes, the
vector yp contains the derivatives at the nodes. The vector
xi contains the points where we want to evaluate the
interpolating function, the vector yi contains the
corresponding values of the interpolating function.
hermite.m . Then use yi =
hermite(x,y,yp,xi)yi = spline(x,[sl;y;sr],xi) yi =
spline(x,y,xi)[Q0,R0] = qr(A,0)
b0 = Q0'*y
c = R0\b0c = A\yxs = fzero('f',[a,b]) for function in m-file
f.mf=inline('sin(x)','x'); xs=fzero(f,[3,4])ode45: Default
for RelTol is 1e-3, default for AbsTol is 1e-6
opts = odeset('RelTol',1e-4,'AbsTol',1e-7);
[t,y] = ode45('f',[t0,T],y0,opts);
ode*, error tolerance, event
locationode45: try this first (uses methods of order 4,5)ode23: sometimes better for lower accuracy (uses methods of
order 2,3)ode113: sometimes better for higher accuracy (uses variable
order) ode15s: for "stiff" problems, high accuracy (uses variable
order)ode23s: for "stiff" problems, low accuracy (uses order
2)You will only receive credit for your homework if you follow the following rules:
For each problem you must hand in
;'' at the end of lines to suppress
the output of intermediate results (especially if these are large
arrays).disp or fprintf commands to for text 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.)If you use Matlab 7 you can also use the
publish command to generate an html file and
print this from your web browser. This printout replaces 1.-3. from above.
tap
matlab and then matlab & . This
starts the integrated enviroment (with editor and debugger). matlab
-nodesktop. In this way you can also use Matlab remotely
(but you won't see any graphs unless you have an X-server running on
your local machine). You can use your favorite editor (nedit,
pico,
vi, emacs) for
writing m-files.