0% found this document useful (0 votes)
28 views12 pages

Integral Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views12 pages

Integral Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Name: Nishat Salsabil

ID: 221538

Assingnment-01

Ans to the question no-01


Addition
a)
clc
clear all
close all
n1=input('enter the number of rows of A matrix:\n')
m1=input('enter the number of columns of A matrix:\n')
A=input('enter the matrix A:\n')
n2=input('enter the number of rows of B matrix:\n')
m2=input('enter the number of columns of B matrix:\n')
B=input('enter the matrix B:\n')
if n1==n2 & m1==m2
C=(-2*A+5*B);
disp('the addition of given two matrices is:')
disp(C)
else
disp('addition is not possible')
end

b)

clc
clear all
close all
Transpose
m=input('enter the number of rows for matrix A:\n')
n=input('enter the number of columns for matrix A:\n')
A=input('enter the matrix A:\n');
B=zeros(m,n);
[m,n]=size(A);
[n,m]=size(B);
for i=1:m
for j=1:n
B(j,i)=A(i,j);
end
end
disp('transpose of A is:')
disp(B)
c)

clc
clear all
close all
m=input('enter the number of rows for matrix A:\n')
n=input('enter the number of columns for matrix A:\n')
A=input('enter the matrix A:\n');
n2=input('enter the number of rows of B matrix:\n')
m2=input('enter the number of columns of B matrix:\n')
B=input('enter the matrix B:\n')
if m==n2 & n==m2
X=(1/2*(A)+B)
disp('the addition of given two matrices is:')
disp(X)
else
disp('addition is not possible')

[p,q]=size(x);
Y=zeros(p,q);
for i=1:p
for j=1:q
Y(j,i)=X(i,j);
end
end
disp('transpose of Y is:')
disp(Y)
end

d) clc
clear all
close all
m=input('Enter the number of rows for matrix A:\n');
n=input('Enter the number of columns for matrix A:\n');
A=input('Enter the elements of matrix A:\n');
C=zeros(m,n);
[m,n]=size(A);
for i=1:m
for j=1:n
C(i,j)=A(j,i);
end
end
X=0.5*(A+C);
Y=0.5*(A-C);
A_reconstructed=X+Y;
disp('Original matrix A:')
disp(A)
disp('Symmetric matrix X:')
disp(X)
disp('Skew-symmetric matrix Y:')
disp(Y)
e)
clc;
close all
m=input('Enter the number of rows for matrix C:\n');
n=input('Enter the number of columns for matrix C:\n');
C=input('Enter the elements of matrix C:\n')
[m,n]=size(C);
isHermitian=true;
for i=1:m
for j=1:n
if C(i,j)~=conj(C(j,i))
isHermitian=false;
break;
end
end
if~isHermitian
break
end
end
if isHermitian
disp('The matrix is Hermitian')
else
disp('The matrix is not Hermitian')
end

Ans to the question no-02

a)

clc
clear all
close all
Ans to the Question no-02
n1=input('enter the number of rows of A matrix:\n')
m1=input('enter the number of columns of A matrix:\n')
A=input('enter the matrix A:\n')
n2=input('enter the number of rows of B matrix:\n')
m2=input('enter the number of columns of B matrix:\n')
B=input('enter the matrix B:\n')
if m1==n2
disp('the multiplication of given two matrices is:')
else
disp(' multiplication is not possible')
end

b)

clc
clear all
close all
n1=input('enter the number of rows of A matrix:\n')
m1=input('enter the number of columns of A matrix:\n')
A=input('enter the matrix A:\n')
n2=input('enter the number of rows of B matrix:\n')
m2=input('enter the number of columns of B matrix:\n')
B=input('enter the matrix B:\n')
if m1==n2
C=A*B
disp('the multiplication of given two matrices is:')
disp(C)
else
disp(' multiplication is not possible')
end

c)

clc
clear all
close all
n1=input('enter the number of rows of A matrix:\n')
m1=input('enter the number of columns of A matrix:\n')
A=input('enter the matrix A:\n')
n2=input('enter the number of rows of B matrix:\n')
m2=input('enter the number of columns of B matrix:\n')
B=input('enter the matrix B:\n')
if m1==n2
C=A*B
disp('the multiplication of given two matrices is:')
disp(C)
else
disp(' multiplication is not possible')
end
if m2==n1
disp('the multiplication of given two matrices is:')
D=B*A
disp(D)
else
disp(' multiplication is not possible')
end
if C==D
disp('AB=BA')
elseif C~=D
disp('AB not equal BA')
end

Ans to the question no-03


clc
clear all
close all
m=input('Enter the number of rows for E:\n');
n=input('Enter the number of columns of E:\n');
E=input('Enter the elements of E')
[m,n]=size(E);if m==n
D=det(E)
if D~=0
oldE=E
for i=1:m
for j=1:n
E(i,:)=[];
E(:,j)=[];
adjE(j,i)=((-1)^(i+j))*det(E);
E=oldE;
end
disp('Adjoint matrix is')
disp(adjE);
end
invE=adjE/D;
disp('Inverse matrix is')
disp(invE)
else
disp('Inverse is not possible')
end
end

Ans to the question no-04


clc
clear all
close all
A=input('enter the coefficient matrix:\n');
B=input('enter the source vector:\n');
N=length(B)
x=zeros(N,1)
D=det(A)
Aold=A
if D~=0
for i=1:N
A(:,i)=B
x(i)=det(A)/D
A=Aold;
end
disp('The desired solution using crameers rule is');
x(:,end)
else
disp('Crameers rule can not be used')
end
Assingnment-02

1. Plot the graph


clc;
clear all;
close all;
x=linspace(-pi ,pi,190);
y=sin(1./x)
plot(x,y,'r ')
xlabel('x');
ylabel('y');
axis('equal'),grid
title('the graph of sin(1/x)')

2. Plot the graph

clc;
clear all;
close all;
x=linspace(-pi ,pi,190);
y=x.*sin(1./x);
plot(x,y,'r ')
xlabel('x');
ylabel('y');
axis('equal'),grid
title('the graph of xsin(1/x)')

3. Plot the graph


clc;
clear all;
close all;
x=linspace(-2*pi,2*pi,100);
y=nthroot(x,3);
plot(x,y,'r');
xlabel('x');
ylabel('y');
axis('equal'),grid;

4. Plot the graph


clc;
clear all;
close all;
x=linspace(-3*pi ,5*pi,190);
y=sec(x);
plot(x,y,'r ')
xlabel('x');
ylabel('y');
axis('equal'),grid
title('the graph of secx')

5. Plot the graph

clc;
clear all;
close all;
x=linspace(-pi ,pi,190);
y=sinh(x);
plot(x,y,'r ')
xlabel('x');
ylabel('y');
axis('equal'),grid
title('the graph of sinh(x)')

6. Plot the graph

clc;
clear all;
close all;
theta=linspace(0,12*pi,1000);
r= theta;
polarplot(theta,r,'k');

7. Plot the graph theta=constant


clc;
clear all;
close all;
constant=linspace(0,12*pi,1000);
theta=constant
polarplot(constant,theta);

8. Plot the graph r=constant

clc;
clear all;
close all;
constant=linspace(0,2*pi,2000);
r= constant;
polarplot(constant,r)
title('the graph of r= constant ')
xlabel('x')
ylabel('y')
axis('equal')
grid on

9. Sketch the graph

clc,
clear all;
close all;
x=linspace(-10,10,100)
y=abs(x+7)+abs(x-9)
plot(x,y,'--')
xlabel('x')
ylabel('y')
axis('equal'),grid

10. Sketch
clc,
clear all;
close all;
t=linspace(-pi,pi,100)
y=exp(-0.4*t).*(sin(t))
plot(t,y,'r')
xlabel('x')
ylabel('y')
axis('equal'),grid

11.sketch the graph y=cost and

clc;
clear all;
close all
t=linspace(0,pi,100);
y=cos(t);
plot(t,y,'--');
xlabel('x');
ylabel('y');
axis('equal'),grid
hold on
x=linspace(-100,100,100)
z=1-(x.*x/2)+(x.*x/24);
plot(x,z,'--');
hold off

12. Write the code for Overlay plots


x=linspace(0,2*pi,100);
y1=sin(x);
plot(x,y1);
hold on
y2=x;
plot(x,y2,'--');
y3=x-(x.^3)/6+(x.^5)/120;
plot(x,y3,'o');
line(x,y3,'marker','o')
legend('y3','y1','y2')
axis([0 5 -1 5])
hold off

13. Write the code for


subplot

t=linspace(0,6*pi,100)
x=cos(t)
y=sin(t)
z=t
subplot(2,2,1),plot3(x,y,z)
subplot(2,2,2),plot3(x,y,z),view(0,90)
subplot(2,2,3),plot3(x,y,z),view(0,0)
subplot(2,2,4),plot3(x,y,z),view(90,0)

14.Write the code for polar graph sketching.


clc
clear all
t=linspace(0,2*pi,200)
r=sqrt(abs(2*sin(5*t)));
polar(t,r)

15. Write the code for Bar graph


t=linspace(0,2*pi,200);
r=sqrt(abs(2*sin(5*t)));
y=r.*sin(t);
bar(t,y)
axis([0 pi 0 inf])

16.Write the graph error bar Graph


x=0:.1:2;
aprx2=x-x.^3/6;
er=aprx2-sin(x);
errorbar(x,aprx2,er)

17) Write the code for overlay plot


clc
close all;
clear all;
r=linspace(-3,3,50);
[x,y]= meshgrid(r,r);
z=-5./(1+x.^2+y.^2);
contour3(z)

18)Write the code for mesh


x=linspace(-3,3,50)
y=x
[x,y]=meshgrid(x,y);
z=-5./(1+x.^2+y.^2);
mesh(z)

19)Write the graph for meshz


x=linspace(-pi,pi/2,50)
y=x
[x,y]=meshgrid(x,y);
z=sin(x.^2)+sin(y.^2);
meshz(x,y,z),axis tight
view(-37.5,50)

(20.)Sketch the graph of y=x.^2.*sin(1./x)

clc;
clear all;
close all;
x=linspace(-pi,pi,2000)
y=x.^2.*sin(1./x)
plot(x,y,'r')
title('the graph of x^2*sin(1/x)');
xlabel('x')
ylabel('y')
axis('equal'),
grid on;
Assingnment-02
a) Volume of integration.
clc;
clear ll;
close all;
syms x y f(x,y)
% considering z=f(x,y);
f(x,y)=3.*x.^3+3*x.^2.*y;
n=input('increment:\n');
sum_f=0;
for i=1:n:3
for j=0:n:2
sum_f=sum_f + double(f(i,j));
end
end
small_area=n.^2;
volume=sum_f*small_area;
disp('the required volume is ');
disp(volume)

b) Surface revolution.
clc;
clear all;
close all;
x=linspace(0,1,1000);
y=x.^3
dx=x(2)-x(1)
surface_area=0
for i=1:length(x)
r= y(i)
dA=2*pi*r*dx
surface_area= surface_area+dA
end
disp(['The surface area is ',num2str(surface_area)])

C) Solve function by integration.

clc;
clear all;
close all;
F1=inline('1-6.*x.^2.*y')
I1=dblquad(F1,0,2,-1,1)
F2=inline('x.^2*y')
I2= dblquad(F2,-1,2,0,1)

You might also like