echo on

%to display the commands

%             ENTERING A MATRIX

a=2; b=3;

c=a*b

v=[7 3 9]

w=[2;6;1]

a=[1 2 3;4 5 6;7 8 9]

b= [11 12 13

24 25 26

27 28 29]

%              TRANSPOSE

v=[1 2 3 4]

v'

a

a'

%              SPECIAL MATRIX CREATORS

c=eye(5)

diag([1 2 3])

v=[1 2 3 4 5]

diag(v)

v=[1; 2; 3; 4; 5;]

b=diag(v)

diag(b)

d=ones(3,4)

d'

t=zeros(1,4)

t=zeros(4,1)

r=rand(2,3)

rand(3)

rand(2,2,2)

b=ceil(rand(2)*10)

%                     LINSPACE

u=linspace(0,0.2,10)

u'

u=linspace(0,0.2,10)'

%                     LOGSPACE

u=logspace(1,5,5)

u=logspace(1,5,4)

x=linspace(1,5,4)

y=10.^x

u=logspace(1,5,4)

%                    INSTEAD OF LOOPS

x=linspace(0,2*pi,7)

s=sin(x);

c=cos(x);

[x',s',c']

%                    ARRAY ADRESSING

a=[1 2 3; 4 5 6; 7 8 9]

a(3,2)

%                    CHANGING ARRAYS

a(3,2)=87

d=eye(3,5)

d(4,2)=9

%                   SIZE OF AN ARRAY

x=0:0.2:4

n=length(x)

x(n)=12

a=zeros(2,3)

size(a)

[nr nc]=size(a)

b=ones(nr,nc)

b=ones(size(a))

%                   GETTING ENTIRE ROWS OR COLUMNS

a=[1 2 3;4 5 6;7 8 9]

a(1,:)

a(:,2)

a(1:2,2:3)

a(:,3)=[45;12;90]

x=rand(4)

rs=reshape(x,2,8)

x(:)

x(:)'

x=rand(1,4)

x(end)

x(end-2)

a

b=a(2:end,1:end-1)

%                   DELETING ENTRIES

x

x(2)=[]

length(x)

x=rand(1,5)

x(1:3)=[]

x=rand(1,8)

x(4:2:8)=[]

%                   MATRIX ARITHMETIC

a=[2 3; 7 11]

a*a

a.*a

v=[1 2]

v*a

%a*v

%                   Error using ==> *

a*v'

%a.*v'

%                   Error using ==> .*

%                   DOT PRODUCT

v*v'

%                   DYADIC

v'*v



v'

v



%                  %COMPLEX VARIABLES

x=1 + 2*i

x=1 + 2*j

y=2 -3*i

x*y

abs(x*y)

angle(x*y)           

%ANGLE IN RADIANS

angle(x*y)/pi*180    

%ANGLE IN DEGREES

x

conj(x)

x*conj(x)

real(x)

imag(x)



%                  %STRINGS

s=['hi','there']

s=['hi',' ','there']

%s=['hi';'there']

%                 ??? Error using ==> vertcat

s=['hi   ';'there']

s'

s(2,2)

s(1,3)

s=str2mat('hi','there')

%                   CAN'T MIX !

s=['root 3 is ',sqrt(3)]

s=['root 3 is ',num2str(sqrt(3))]

%                   FANCIER

s=sprintf('root 3 is %9.5f',sqrt(3))

s=sprintf('root 3 is %9.5e',sqrt(3))

                  %POLYNOMAILS

              %represented in descending powers !

c=[1,2,1]

polyval(c,1)

polyval(c,0)

polyval(c,-1)

p=conv(c,c)

deconv(p,c)

c= [1 2 2]

deconv(p,c)

c= [1 2 1]

%            get the order wrong

deconv(c,p)

polyder(c)

%            construct a polynomial with specified roots

poly([-1,0,1])

%            fitting data with a polynomial

x=linspace(1,5,5)       

%make a perfect line

y=x*3

y(end)=16            

%experimental error

p=polyfit(x,y,1)     

%polynomial fit

lin=polyval(p,0)     

%evaluate fit

lin=polyval(p,x)     

%evaluate for all x

plot(x,y,x,lin)

roots([1,2,1])       

%find roots of a given polynomial

roots([1,2,4])



p1=[1 1]             

%partial fraction decomposition

p2 = [3 2 5]

residue(p1,p2)       

%What did we just do?

help residue

%                     READ THE HELP

[R,P,K]=residue(p1,p2)

