Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practice in labs:

a= [1 2 3; 4 5 6; 7 8 9;]
a(2,:) % 2 is for row and : is for column
a(:,2:3) % all rows and 2nd to 3rd column
a(:,2)=[] % all rows 2nd column delete krky [] is for deleting the 2nd
column

a= [1 2 3; 4 5 6; 7 8 9;]
b= a([2 3],[1 2])

Ans:

a=

1 2 3

4 5 6

7 8 9

b=

4 5

7 8

% for finding the size of the matrix


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

a= [1 2 3; 4 5 6; 7 8 9;]
a' % this is for transpose

% for solving inverse of a matrix


a=[1 2 3; 4 5 6; 7 8 0;]
b=[1; 1; 1;]
x=inv(a)*b
or
a=[1 2 3; 4 5 6; 7 8 0;]
b=[1; 1; 1;]
x=a\b
% finding the determinant of a matrix
a=[1 2 3; 4 5 6; 7 8 0;]
b=[1; 1; 1;]
det(a)

% finding the factorial


a=factorial(5)

% but if we do in this way then we have a choice to multiply


range of numbers acc to our choice of starting and ending
value
prod(1:5)

g=input('enter valu')

enter value

% finding the average but by the value of your choice


g1=input('enter value');
g2=input('enter value');
g3=input('enter value');
a=(g1+g2+g3)/3

a=2;
b=2;
c=4;
d=b*b-4*a*c;
if d<0
disp('roots are imaginary')
else
disp('roots are real')
end

polynomial solution:
g=poly([-1+2j -1-2j -1 0 0]);
poly2str(g,'s')

f=[2 2 2];
poly2str(f,'s')
g=poly([-1+2j -1-2j -1 0 0]);
poly2str(g,'s')
h=conv(f,g)

a=2;
b=2;
c=4;
d=b*b-4*a*c;
if d<0
disp('pakistan')
elseif d==0
disp('pak')
else
disp('input')
end

You might also like