Computing Vector Norms:
Type help norm to learn how to compute 1-norm, 2-norm, p-norm
and infinity-norm for a given vector using MatLab m-function
norm. The following is the m-file which computes 1-norm, 2-norm
and infinity-norm of vector xk-x where
xk=[ksin(1/k); 3+1/k; cos(k)/ek]. You recieved
a hard copy of the graph in class last Thursday.
clf
clear
n=input('input n = ');
vsol=[1;3;0];
for i=1:n
vv(1,i)=i*sin(1/i);
vv(2,i)=3+1/i;
vv(3,i)=cos(i)/exp(i);
difv(:,i)=vv(:,i)-vsol;
nor1(i,1)=norm(difv(:,i),1);
nor2(i,1)=norm(difv(:,i),2);
norinf(i,1)=norm(difv(:,i),inf);
end;
semilogy(nor1,'-.')
hold
semilogy(nor2,':')
semilogy(norinf,'--')
hold off
title('||x(k)-x||, where x(k)=[k*sin(1/k) 3+1/k cos(k)/e^k], x=[1;3;0]')
xlabel('index k')
ylabel('log(||x(k)-x||)')
text(3,1,'-.-. 1-norm, .... 2-norm, ---- infinity-norm')