I always try to be generous if you need an extension, or miss the deadline by a little bit, as long as you are honest with me. But if you lie about the time you hand in the homework I have to consider this academic dishonesty.
num2bin.m
and bin2num.m (note that you
have to put the files where
Matlab can find them)A = sparse(iv,jv,av);E.g., the full matrix given by A = [0 7 0; 0 0 8; 9 0 0] can be defined as a sparse matrix by
A = sparse([1 2 3],[2 3 1],[7 8 9])
divdiff computes the divided differences
d1=f[x1,...,xn],
d2=f[x2,...,xn],...,dn=f[xn]
Algorithm d=divdiff(x,y)
d := y
For k=1 to n-1
For i=1 to n-k
di :=
(di+1-di)/(xi+k-xi)
evnewt evaluates the interpolating polynomial at the point t
Algorithm v=evnewt(d,x,t)
v := d1
For i=2 to n
v := v·(t-xi) + di
h = (b-a)/(n-1); xj = a + (j-1)h for j = 1,...,nIn Matlab you can use x = linspace(a,b,n) to define a vector of equidistant nodes.
|(x-x1)...(x-xn)| ≤ hn(n-1)!/4 for x in [a,b]Chebyshev nodes on the interval [a,b] are given by
xj = (a+b)/2 + cos(The node polynomial has the bound(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)pp = spline(x,y);
yi = ppval(pp,xi);
|| Ax - b || = minimal.
[Q,R] = qr(A,0)
b = Q'*y
c = R\bc = A\y
xs = fzero(@f,[a,b])
where the function f is given by the m-file f.m.
f=@(x)sin(x); xs=fzero(f,[3,4])function y = f(x)Then use x = fsolve(@f,x0) where x0 is the initial guess.
y = ...
function [y,A] = f(x)Then use
y = ...
A = ...
opt = optimset('Jacobian','on'); x = fsolve(@f,x0,opt);where x0 is the initial guess.
opt = optimset('TolFun',1e-5,'TolX',1e-5);There are many other options, type doc fsolve for more information.
x = fsolve(@f,x0,opt);
Q = w1f(x1) + ... + wnf(xn)with nodes x1,...,xn and weights w1,...,wn.
xt = (a+b)/2 + x*(b-a)/2; wt = (b-a)/2*w;
f = @(t,y) [y(2);-2*y(2)-3*y(1)+sin(t)];
[ts,ys] = Euler(f,[0,5],[2;-1],20);
plot(ts,ys(:,1),'.-'); hold all
[ts,ys] = Euler(f,[0,5],[2;-1],100);
plot(ts,ys(:,1),'.-'); hold off; legend('N=20','N=100')