5A&5B Matlab 21BEC2166

You might also like

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

EXPERIMENT 5A&5B

NAME: Anand Kholwadiya

REG NO: 21BEC2166

CLASS SLOT: L9 +L10

FACULTY: Ezhilmaran.D

EXPERIMENT-5A
EXAMPLE-1:
MATH LAB CODE:
clc
clear all
syms x y t
f=input('Enter the components of 2D vector function [u,v] ');
r=input('Enter x,y in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y},r);
Fdr=sum(F.*dr);
I=int(Fdr,t,a,b)
P(x,y)=f(1);Q(x,y)=f(2);
x1=linspace(-2*pi,2*pi,10); y1=x1;
[X,Y] = meshgrid(x1,y1);
U=P(X,Y); V=Q(X,Y);
quiver(X,Y,U,V,1.5)
hold on
t1=linspace(0,2*pi);
x=subs(r(1),t1);y=subs(r(2),t1);
plot(x,y,'r')

INPUT:
Enter the components of 2D vector function [u,v]

[x*y^2 x^2*y]

Enter x,y in parametric form


[t+sin((pi*t)/2) t+cos((pi*t)/2)]
Enter the limits of integration for t in the form [a,b]
[0,1]

OUTPUT:
I=2
EXAMPLE-2:
MATH LAB CODE:
clc
clear all
syms x y z t
f=input('Enter the components of 3D vector function [u,v,w] ');
r=input('Enter x,y,z in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y,z},r);
Fdr=sum(F.*dr);
I=int(Fdr,t,a,b)
P(x,y,z)=f(1);Q(x,y,z)=f(2); R(x,y,z)=f(3);
x1=linspace(0,1,10); y1=x1; z1=x1;
[X,Y,Z] = meshgrid(x1,y1,z1);
U=P(X,Y,Z); V=Q(X,Y,Z); W=R(X,Y,Z);
quiver3(X,Y,Z,U,V,W,1.5)
hold on
t1=linspace(0,1,10);
x=subs(r(1),t1);y=subs(r(2),t1);z=subs(r(3),t1);
plot3(x,y,z,'r')

INPUT:
Enter the components of 3D vector function [u,v,w]
[x*y y*z z*x]
Enter x,y,z in parametric form
[t t^2 t^3]
Enter the limits of integration for t in the form [a,b]
[0,1]

OUTPUT:
I = 27/28
EXERCISE-1:
MATH LAB CODE:
clc
clear all
syms x y z t
f=input('Enter the components of 3D vector function [u,v,w] ');
r=input('Enter x,y,z in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y,z},r);
Fdr=sum(F.*dr);
I=int(Fdr,t,a,b)
P(x,y,z)=f(1);Q(x,y,z)=f(2); R(x,y,z)=f(3);
x1=linspace(0,1,10); y1=x1; z1=x1;
[X,Y,Z] = meshgrid(x1,y1,z1);
U=P(X,Y,Z); V=Q(X,Y,Z); W=R(X,Y,Z);
quiver3(X,Y,Z,U,V,W,1.5)
hold on
t1=linspace(0,1,10);
x=subs(r(1),t1);y=subs(r(2),t1);z=subs(r(3),t1);
plot3(x,y,z,'r')

INPUT:
Enter the components of 3D vector function [u,v,w]
[y*z x*z x*y+2*z]
Enter x,y,z in parametric form
[3*t+1 6*t 5*t-2]
Enter the limits of integration for t in the form [a,b]
[0,1]
OUTPUT:
I=
77

EXERCISE-2:
MATH LAB CODE:
clc
clear all
syms x y t
f=input('Enter the components of 2D vector function [u,v] ');
r=input('Enter x,y in parametric form');
I=input('Enter the limits of integration for t in the form [a,b]');
a=I(1);b=I(2);
dr=diff(r,t);
F=subs(f,{x,y},r);
Fdr=sum(F.*dr);
I=int(Fdr,t,a,b)
P(x,y)=f(1);Q(x,y)=f(2);
x1=linspace(-2*pi,2*pi,10); y1=x1;
[X,Y] = meshgrid(x1,y1);
U=P(X,Y); V=Q(X,Y);
quiver(X,Y,U,V,1.5)
hold on
t1=linspace(0,2*pi);
x=subs(r(1),t1);y=subs(r(2),t1);
plot(x,y,'r')

INPUT:
Enter the components of 2D vector function [u,v]
[x^2 y^2]
Enter x,y in parametric form
[3*t-1 6*t+2]
Enter the limits of integration for t in the form [a,b]
[0 1]

OUTPUT:
I = 171

EXPERIMENT-5B
EXAMPLE-1:
MATH LAB CODE:
clear
clc
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]: ');
M(x,y)=F(1); N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as [r1(t) r2(t)]: ');
r1=r(1);r2=r(2);
P=M(r1,r2);Q=N(r1,r2);
dr=diff(r,t);
F1=sum([P,Q].*dr);
T=input('Enter the limits of integration for t [t1,t2]: ');
t1=T(1);t2=T(2);
LHS=int(F1,t,t1,t2);
yL=input('Enter limits for y in terms of x: [y1,y2]: ');
xL=input('Enter limits for x as constants: [x1,x2]: ');
y1=yL(1);y2=yL(2);x1=xL(1);x2=xL(2);
F2=diff(N,x)-diff(M,y);
RHS=int(int(F2,y,y1,y2),x,x1,x2);
if(LHS==RHS)
disp('LHS of Greens theorem=')
disp(LHS)
disp('RHS of Greens theorem=')
disp(RHS)
disp('Hence Greens theorem is verified.');
end

INPUT:
Enter the vector function M(x,y)i+N(x,y)j in the form [M N]:
[-y,x]
Enter the parametric form of the curve C as [r1(t) r2(t)]:
[cos(t) sin(t)]
Enter the limits of integration for t [t1,t2]:
[0,2*pi]
Enter limits for y in terms of x: [y1,y2]:
[-sqrt(1-x^2) sqrt(1-x^2)]
Enter limits for x as constants: [x1,x2]:
[-1,1]

OUTPUT:
LHS of Greens theorem=

2*pi

RHS of Greens theorem=

2*pi
Hence Greens theorem is verified.
EXERCISE-1:
MATH LAB CODE:
clear
clc
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]: ');
M(x,y)=F(1); N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as [r1(t) r2(t)]: ');
r1=r(1);r2=r(2);
P=M(r1,r2);Q=N(r1,r2);
dr=diff(r,t);
F1=sum([P,Q].*dr);
T=input('Enter the limits of integration for t [t1,t2]: ');
t1=T(1);t2=T(2);
LHS=int(F1,t,t1,t2);
yL=input('Enter limits for y in terms of x: [y1,y2]: ');
xL=input('Enter limits for x as constants: [x1,x2]: ');
y1=yL(1);y2=yL(2);x1=xL(1);x2=xL(2);
F2=diff(N,x)-diff(M,y);
RHS=int(int(F2,y,y1,y2),x,x1,x2);
if(LHS==RHS)
disp('LHS of Greens theorem=')
disp(LHS)
disp('RHS of Greens theorem=')
disp(RHS)
disp('Hence Greens theorem is verified.');
end

INPUT:
Enter the vector function M(x,y)i+N(x,y)j in the form [M N]:
[x^2-y^3,x^3+y^2]
Enter the parametric form of the curve C as [r1(t) r2(t)]:
[8*cos(t),4* sin(t)]
Enter the limits of integration for t [t1,t2]:
[0,2*pi]
Enter limits for y in terms of x: [y1,y2]:
[-sqrt((64-x^2)/4),sqrt((64-x^2)/4)]
Enter limits for x as constants: [x1,x2]:
[-8,8]

OUTPUT:
LHS of Greens theorem=
1920*pi

RHS of Greens theorem=


1920*pi

Hence Greens theorem is verified.


EXERCISE-2:
MATH LAB CODE:
clear
clc
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]: ');
M(x,y)=F(1); N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as [r1(t) r2(t)]: ');
r1=r(1);r2=r(2);
P=M(r1,r2);Q=N(r1,r2);
dr=diff(r,t);
F1=sum([P,Q].*dr);
T=input('Enter the limits of integration for t [t1,t2]: ');
t1=T(1);t2=T(2);
LHS=int(F1,t,t1,t2);
yL=input('Enter limits for y in terms of x: [y1,y2]: ');
xL=input('Enter limits for x as constants: [x1,x2]: ');
y1=yL(1);y2=yL(2);x1=xL(1);x2=xL(2);
F2=diff(N,x)-diff(M,y);
RHS=int(int(F2,y,y1,y2),x,x1,x2);
if(LHS==RHS)
disp('LHS of Greens theorem=')
disp(LHS)
disp('RHS of Greens theorem=')
disp(RHS)
disp('Hence Greens theorem is verified.');
end

INPUT:
Enter the vector function M(x,y)i+N(x,y)j in the form [M N]:
[x+y,y-x]
Enter the parametric form of the curve C as [r1(t) r2(t)]:
[cos(t), sin(t)]
Enter the limits of integration for t [t1,t2]:
[0,2*pi]
Enter limits for y in terms of x: [y1,y2]:
[-(sqrt(1-x^2)),sqrt(1-x^2)]
Enter limits for x as constants: [x1,x2]:
[-1,1]

OUTPUT:
LHS of Greens theorem=
-2*pi

RHS of Greens theorem=


-2*pi

Hence Greens theorem is verified.

EXERCISE-3:
MATH LAB CODE:
clear
clc
syms x y t
F=input('Enter the vector function M(x,y)i+N(x,y)j in the form [M N]: ');
M(x,y)=F(1); N(x,y)=F(2);
r=input('Enter the parametric form of the curve C as [r1(t) r2(t)]: ');
r1=r(1);r2=r(2);
P=M(r1,r2);Q=N(r1,r2);
dr=diff(r,t);
F1=sum([P,Q].*dr);
T=input('Enter the limits of integration for t [t1,t2]: ');
t1=T(1);t2=T(2);
LHS=int(F1,t,t1,t2);
yL=input('Enter limits for y in terms of x: [y1,y2]: ');
xL=input('Enter limits for x as constants: [x1,x2]: ');
y1=yL(1);y2=yL(2);x1=xL(1);x2=xL(2);
F2=diff(N,x)-diff(M,y);
RHS=int(int(F2,y,y1,y2),x,x1,x2);
if(LHS==RHS)
disp('LHS of Greens theorem=')
disp(LHS)
disp('RHS of Greens theorem=')
disp(RHS)
disp('Hence Greens theorem is verified.');
end

INPUT:
Enter the vector function M(x,y)i+N(x,y)j in the form [M N]:
[sin(y)*exp(x), cos(y) *exp(x)]
Enter the parametric form of the curve C as [r1(t) r2(t)]:
[3* cos(t)-1,2* sin(t)+3]
Enter the limits of integration for t [t1,t2]:
[0,2*pi]
Enter limits for y in terms of x: [y1,y2]:
[3-sqrt(36-4*(x+1)^2)/3,3+sqrt(36-4*(x+1)^2)/3]
Enter limits for x as constants: [x1,x2]:
[2,4]

OUTPUT:
LHS of Greens theorem=
0

RHS of Greens theorem=


0

Hence Greens theorem is verified.

You might also like