You are on page 1of 7

AIM: Write a MATLAB program to perform matrix

operations on given two matrices and also find


transpose inverse and determinant.

function[]=matrix_operations()
clc;
close all;
A=input('ENTER THE ELEMENTS OF FIRST MATRIX ROW-
WISE');
B=input('ENTER THE ELEMENTS OF FIRST MATRIX ROW-
WISE');
add=A+B;
disp('ADDITION');
disp(add);
sub=A-B;
disp('SUBTRACTION');
disp(sub);
mul=A*B;
disp('MULTIPLY');
disp(mul);
C=A';
disp('TRANSPOSE');
disp(C);
D=inv(A);
disp('INVERSE');
disp(D);
e=det(A);
disp('DETERMINANT');
disp(e);
end
AIM: Write a MATLAB program to find the real
root of the equation x*log10(x)-1.2 =0 by using
Newton Raphson method.

function[]=newton_raphson_method()
clc;
close all;
f=inline('x*log10(x)-1.2');
df=inline('log10(x)+0.434294');
a=input('enter the value of a\n');
b=input('enter the value of b\n');
aerr=input('enter the value of aerr\n');
maxitr=input('enter the value of maxitr\n')
if(f(a)*f(b)<0)
x0=(a+b)/2;
for itr=1:1:maxitr
h=f(x0)/df(x0);
x1=x0-h;
fprintf('itr no %d,x=%f\n',itr,x1);
if(abs(h)<=aerr)
fprintf('after %d no of itrs
x=%f\n',itr,x1);
return;
end
x0=x1;
end
fprintf('max no of itrs is not sufficient');
else
fprinf('NO roots or even roots exist');
end
end

You might also like