[X1,X2] = meshgrid(linspace(-4,4,100),linspace(-5,5,100)); contour(X1,X2, X1 + X2 - X1.*X2 - 2,[0 0],'b-'); hold on contour(X1,X2, X1 - X2 + X1.^3 + 3,[0 0],'r:'); hold offNote that you must use .* ./ .^ instead of * / ^.
num2bin.m
and bin2num.m
(put them in the same directory/folder
as your other m-files.)
c = norm(A,1)*invnormest(L,U)For the infinity-norm condition number use
c = norm(A,Inf)*invnormest(U',L')This works also for a sparse matrix A (see right below).
A = sparse(iv,jv,av);Example: The full matrix given 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
d_{1}=f[x_{1},...,x_{n}],
d_{2}=f[x_{2},...,x_{n}],...,d_{n}=f[x_{n}]
Algorithm d=divdiff(x,y)
d := y
For k=1 to n-1
For i=1 to n-k
d_{i} :=
(d_{i+1}-d_{i})/(x_{i+k}-x_{i})
evnewt evaluates the interpolating polynomial at the point t
Algorithm v=evnewt(d,x,t)
v := d_{1}
For i=2 to n
v := v·(t-x_{i}) + d_{i}
h = (b-a)/(n-1); x_{j} = 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-x_{1})...(x-x_{n})| ≤ h^{n}(n-1)!/4 for x in [a,b]Chebyshev nodes on the interval [a,b] are given by
x_{j} = (a+b)/2 + cos(π(j-1/2)/n) (b-a)/2 for j = 1,...,n.The node polynomial has the bound
|(x-x_{1})...(x-x_{n})| ≤ 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);
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');where x0 is the initial guess.
x = fsolve(@f,x0,opt);
opt = optimset('TolFun',1e-5,'TolX',1e-5);There are many other options, type doc fsolve for more information.
x = fsolve(@f,x0,opt);