You are on page 1of 9

LAB1

MATLAB PROGRAM:-

FLOWCHART:-
CODE:-
function [] = matrix_1 ()
clc;
clear all;
A = input( 'Enter the elements of Matrix A : ' );
B = input( 'Enter the elements of Matrix B : ' );
sum = A+B;
diff = A-B;
prod = A*B;
transA = A';
detA = det(A);
invA = inv(A);
disp ( 'The Sum of Two Matrices is:' );
disp ( sum );
disp ( 'The Difference of Two Matrices is:' );
disp (diff);
disp ( 'The Product of Two Matrices is:' );
disp ( prod );
disp ( 'The Transpose of Matrix A is:' );
disp (transA);
disp ( 'The Determinant of Matrix A is:' );
disp (detA);
disp ( 'The Inverse of Matrix A is:' );
disp (invA);
end
OUTPUT:-
Enter the elements of Matrix A : [1,2,3;4,5,6;7,8,9]
Enter the elements of Matrix B : [1,2,3;2,3,4;5,6,7]
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
1.541976e-18.
> In matrix_1 (line 11)

The Sum of Two Matrices is:


2 4 6
6 8 10
12 14 16

The Difference of Two Matrices is:


0 0 0
2 2 2
2 2 2

The Product of Two Matrices is:


20 26 32
44 59 74
68 92 116

The Transpose of Matrix A is:


1 4 7
2 5 8
3 6 9

The Determinant of Matrix A is:


6.6613e-16

The Inverse of Matrix A is:


1.0e+16 *

-0.4504 0.9007 -0.4504


0.9007 -1.8014 0.9007
-0.4504 0.9007 -0.4504

>>
LAB2
MATLAB PROGRAM:-

FLOWCHART:-
CODE:-
function []= Regula_Falsi ()
clc;
clear all;
a=input( 'Enter the value of a: ' );
b=input( 'Enter the value of b: ' );
function[y]=f(x)
y= cos (x)-x* exp (x);
end
function [ z ]= regula (a,b,fa,fb)
z=(a*fb-b*fa)/(fb-fa);
end
if (f(a)*f(b)< 0 )
allow_error=input( 'Enter the allowed error: ' );
max_itr=input( 'Enter maximum number of iterations: ' );
x0=regula(a,b,f(a),f(b));
for itr= 1 : 1 :max_itr
fprintf ( 'Iteration number = %d , root = %f\n' ,itr,x0);
if (f(a)*f(x0)< 0 )
b = x0;
else a = x0;
end
x1 = regula(a,b,f(a),f(b));
if ( abs (x1-x0)<allow_error)
fprintf ( 'After %d number of iterations using REGULA FALSI
METHOD ,root=%f\n' ,itr,x1);
return
end
x0 = x1;
end
fprintf ( 'The number of iteration entered is insufficient' );
else
fprintf ( 'There is no root or even numbers of root' );
end
end
OUTPUT:-
CASE 1:-
Enter the value of a: 1
Enter the value of b: 2
There is no root or even numbers of root>>

CASE 2:-
Enter the value of a: 0
Enter the value of b: 1
Enter the allowed error: 0.001
Enter maximum number of iterations: 25
Iteration number = 1 , root = 0.314665
Iteration number = 2 , root = 0.446728
Iteration number = 3 , root = 0.494015
Iteration number = 4 , root = 0.509946
Iteration number = 5 , root = 0.515201
Iteration number = 6 , root = 0.516922
After 6 number of iterations using REGULA FALSI METHOD ,root=0.517485
>>
CASE 3:-
Enter the value of a: 0
Enter the value of b: 2
Enter the allowed error: 0.001
Enter maximum number of iterations: 2
Iteration number = 1 , root = 0.123501
Iteration number = 2 , root = 0.223208
The number of iteration entered is insufficient>>
LAB 3
MATLAB PROGRAM:-

FLOWCHART
CODE:-
function [] = Newton_method ()
clc;
clear all;
a = input( 'Enter value of a: ' );
b = input( 'Enter value of b: ' );
function [ y ] = f (x)
y = x* log10 (x)-( 1.2 );
end
function [ z ] = df (x)
z = ( 1 / log ( 10 ))+ log10 (x);
end
if (f(a)*f(b)< 0 )
allow_error = input( 'Enter the allowed error: ' );
max_itr = input( 'Enter maximum number of iterations: ' );
x0 = (a+b)/ 2 ;
for itr = 1 : 1 :max_itr
h=f(x0)/df(x0);
x1=x0-h;
fprintf ( 'Iteration number = %d, root = %f\n' ,itr,x0);
if ( abs (h)<allow_error)
fprintf ( 'After %d number of iterations using Bisection Method,root
= %f\n' ,itr,x1);
return ;
end
x0 = x1;
end
fprintf ( 'The maximum number of iteration entered is insufficient to
calculate the root' );
else
fprintf ( 'There are no root or even number of roots between %f and %f'
,a,b);
end
end
CASE 1:-
Enter value of a: 0
Enter value of b: 1
There are no root or even number of roots between 0.000000 and 1.000000>>

CASE 2:-
Enter the value of a: 0
Enter the value of b: 1
Enter the allowed error: 0.001
Enter maximum number of iterations: 25
Iteration number = 1 , root = 0.314665
Iteration number = 2 , root = 0.446728
Iteration number = 3 , root = 0.494015
Iteration number = 4 , root = 0.509946
Iteration number = 5 , root = 0.515201
Iteration number = 6 , root = 0.516922
After 6 number of iterations using REGULA FALSI METHOD ,root=0.517485
>>
CASE 3:-
Enter the value of a: 0
Enter the value of b: 2
Enter the allowed error: 0.001
Enter maximum number of iterations: 2
Iteration number = 1 , root = 0.123501
Iteration number = 2 , root = 0.223208
The number of iteration entered is insufficient>>

You might also like