%-- 10/31/2014 2:30 PM --%

>> dd=1:3

dd =

     1     2     3

>> A=diag(dd)

A =

     1     0     0
     0     2     0
     0     0     3


>> d1=randi(9,4,1)

d1 =

     6
     1
     3
     5

>> A=diag(d1)

A =

     6     0     0     0
     0     1     0     0
     0     0     3     0
     0     0     0     5

>> d2=dd

d2 =

     1     2     3

>> A=diag(d1) + diag(d2,1)

A =

     6     1     0     0
     0     1     2     0
     0     0     3     3
     0     0     0     5

>> A=diag(d1) + diag(d2,-1)

A =

     6     0     0     0
     1     1     0     0
     0     2     3     0
     0     0     3     5

>> diag(d2,2)

ans =

     0     0     1     0     0
     0     0     0     2     0
     0     0     0     0     3
     0     0     0     0     0
     0     0     0     0     0

>> diag(d2,-2)

ans =

     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     2     0     0     0
     0     0     3     0     0

>> f = inline('exp(x).*cos(2*pi*x)')

f =
     Inline function:
     f(x) = exp(x).*cos(2*pi*x)

>> f(0)

ans =

     1

>> f(1)

ans =

    2.7183

>> x=1:3

x =

     1     2     3

     
>> f(x)

ans =

    2.7183    7.3891   20.0855

 