Escolar Documentos
Profissional Documentos
Cultura Documentos
LAB MANUAL
BATCH MEMBERS
1. ………………………………………………………………………………….
2. ………………………………………………………………………………….
3. ………………………………………………………………………………….
Exercise
i. Find the Product of
a) A & B
b) B & C
c) A & C
d) C & B
e) C & A
ii. Find the Transpose of matrix A.
iii. Find the inverse of matrix B.
iv. Find the determinant of matrix C.
v. Find the difference of matrix A & C ; A & B.
Solution
Plotting in MATLAB
>> x = linspace(-5,5);
>> y = x.^2;
>> y2 = cos(x);
>> y3 = x.^3;
>> y4 = x.^4;
Exercise
3. How to open two figure windows? Now open two figure windows and draw or plot the curve
between (x,y2) & (x,y4).
4. Create a new x
>> x = ( 0:0.1:2*pi);
Now plot(x,sin(x)); showing ‘x’ axis as (‘Angle(radian)’) and ‘y’ axis as (‘Amplitude’)
and the ‘title’ as (‘Sinusoidal’)
Exercise
Solution
for j=m:1-2
for i=j-1:-1:1
c(i,:)=c(i,:)-c(j,:)*(c(i,j)/c(j,j));
end
end
for s=1:m
c(s,:)=c(s,:)/c(s,s);
x(s)=c(s,n);
end
disp('Gauss-Jordan method');
c
x'
A =[2 -4 1
6 2 -1
-2 6 -2];
clc;
clear all;
close all;
x=[5 6 9 11];
a=15;
ans1=((a-y(2))*(a-y(3))*(a-y(4)))*x(1)/((y(1)-y(2))*(y(1)-y(3))*(y(1)-y(4)));
ans2=((a-y(1))*(a-y(3))*(a-y(4)))*x(2)/((y(2)-y(1))*(y(2)-y(3))*(y(2)-y(4)));
ans3=((a-y(1))*(a-y(2))*(a-y(4)))*x(3)/((y(3)-y(1))*(y(3)-y(2))*(y(3)-y(4)));
ans4=((a-y(1))*(a-y(2))*(a-y(3)))*x(4)/((y(4)-y(1))*(y(4)-y(2))*(y(4)-y(3)));
m=ans1+ans2+ans3+ans4;
NUMERICAL INTEGRATION
clc;
clear all;
close all;
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
end
l=length(x);
answer=(h/2)*((y(1)+y(l))+2*(sum(y)-y(1)-y(l)))
clc;
clear all;
close all;
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
end
l=length(x);
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))
clc;
clear all;
close all;
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
end
l=length(x);
answer=(3*h/8)*((y(1)+y(l))+3*(y(2)+y(3)+y(5)+y(6))+2*(y(4)))
function a = runge_kutta(df)
% asking initial conditions
switch r
case 1
% calculating the value of h
n =ceil( (x1-x0)/sqrt(tol));
h = ( x1 - x0)/n;
for i = 1 : n
X(1,1) = x0; Y (1,1) = y0;
k1 = h*feval( df , X(1,i), Y(1,i));
k2 = h*feval( df , X(1,i) + h , Y(1,i) + k1);
k = 1/2* ( k1+ k2);
X( 1, i+1) = X(1,i) + h;
Y( 1 ,i+1) = Y(1,i) + k;
end
case 2
% calculating the value of h
n =ceil( (x1-x0)/nthroot(tol,3));
h = ( x1 - x0)/n;
for i = 1 : n
X(1,1) = x0; Y (1,1) = y0;
k1 = h*feval( df , X(1,i), Y(1,i));
k2 = h*feval( df , X(1,i) + h/2, Y(1,i) + k1);
k3 = h*feval( df , X(1,i) + h, Y(1,i) + k2);
k = 1/6* ( k1+ 4*k2 + k3);
X( 1, i+1) = X(1,i) + h;
Y( 1 ,i+1) = Y(1,i) + k;
end
end
%displaying results
%displaying graph
x = 1:n+1;
y = Y(1,n+1)*ones(1,n+1) - Y(1,:);
plot(x,y,'r')
xlabel = (' no of interval ');
ylabel = ( ' Error ');