Calculus For Engineers Lab Report
Calculus For Engineers Lab Report
1
2.PLOTTING
CARDIOD
2
%find the area of the region bounded below by the line %y =
x^2+3*x and above by the curve y=2x-x^2 + 1 clc clear all syms x y
plot_range=[-1,1]
plot_range = 1×2
-1 1
f1 = x^2+3*x
f1 =
y = 2*x - x^2 + 1, f2 = y
y
=
f2 =
range=[-2,0]
range = 1×2
-2 0
ezplot(f1)
hold on
ezplot(f2)
r1 = sort(double(solve(f1-f2)))
r1 = 2×1
-1.0000
0.5000
area=int(f1-f2,r1(1),r1(2))
area =
range = (r1(1):0.1:r1(2))
range = 1×16
-1.0000 -0.9000 -0.8000 -0.7000 -0.6000 -0.5000 -0.4000 -0.3000
a = subs(f1,range)
a =
b = subs(f2, range)
b =
3
1
ezplot(f1)
hold on
ezplot(f2)
fplot(f1, [-3,3], 'r', 'LineWidth',1.5)
fplot(f2, [-3,3], 'b', 'LineWidth',1.5)
fill([range, fliplr(range)],[a, fliplr(b)], [0,1,0],
'LineStyle','none') xlabel('x') ylabel('y')
title('area by curves')
legend('shaded area', 'y = x^2+3*x', 'y=2x-x^2 +
1') hold on
f1 = -x^2+6
4
f1 =
y = x^2 - 2*x + 2, f2 = y
y
=
f2 =
r1 = sort(double(solve(f1-f2)))
r1 = 2×1
-1
2
area= nt(f1-f2,r1(1),r1(2))
i
area =
range = (r1(1):0.1:r1(2))
range = 1×31
-1.0000 -0.9000 -0.8000 -0.7000 -0.6000 -0.5000 -0.4000 -0.3000
a = subs(f1,range)
a =
b = subs(f2, range)
b =
ezplot(f1)
hold on
ezplot(f2)
fplot(f1,[-3,3], 'b', 'LineWidth'
,1.5)
fplot(f2,[-3,3], 'r', 'LineWidth'
,1.5)
xlabel('x')
ylabel('y')
title('area by curves')
legend('shaded area', 'y = x^2+3*x', 'y=2x-x^2 + 1')
fill([range,fliplr(range)],[a,fliplr(b)],[1,0,1], 'LineStyle'
,'none')
hold on
5
%find the area enclosed by the leminiscale r^2 = 4 cos
2*theta clc clear all syms r theta
r = 2*sqrt(cos(2*theta))
r =
ezpolar(r,[0,2*pi])
Warning: Imaginary parts of complex X and/or Y arguments ignored
title('lemini scale')
6
1
a = 5
r = a*(1+cos(theta))
r =
ezpolar(r,[0,2*pi])
title('cardiod')fill(r.*)
7
Error using fill
Not enough input arguments.
8
3. LAGRANGE
MULTIPLIER
METHOD
9
1.
%Write a programme to find maximum and minimum between 2 numbers
clc clear all syms a b
a=input('enter 1st value')
a =3
b =5
minimum=min(a,b)
minimum = 3
maximum=max(a,b)
maximum = 5
disp(x)
3 is less than 5
2.(a)
THREE VARIABLES MAX
%fprintf('%d is biggest number ',a)
clc clear all syms a b
a=input('enter 1st value')
a =4
b =5
c =6
minimum=min(min(a,b),c)
minimum = 4
maximum=max(max(a,b),c)
maximum = 6
4 is smallest number
b =5
c =6
3.
%differentiation clc clear
all syms x y f=x^3
+3*x*y^2 - 3*x
f=
fx=diff(f,x)
fx =
fy=diff(f,y)
fy =
[xc,yc]=solve([fx,fy],[x,y])
xc =
yc =
fxx=diff(fx,x); fyy=diff(fy,y);
fxy=diff(fx,y); r=subs(fxx,{x,y},{xc,yc});
D=fxx*fyy-fxy^2;
D=subs(D,{x,y},{xc,yc}); c=1; for i=1:length(D) if D(i)>0 if r(i)>0
fprintf('(%f,%f) is a point of minima\n',xc(i),yc(i)); elseif r(i)<0
fprintf('(%f,%f) is a point of maxima\n',xc(i),yc(i)); end elseif D(i)<0
fprintf('At (%f,%f) is a saddle point\n',xc(i),yc(i)); ezsurf(f,[-1.5,1.5,-
1.5,1.5]); end end
f =
g =
F=f+l*g
F=
Fx=diff(F,x);
Fy=diff(F,y);
[l,u,v]=solve(Fx==0,Fy==0,g,[l,x,y])
l=
u =
v =
F_val=subs(F,{x,y},{u,v})
F_val =
[maxv, i]=max(F_val)
maxv = i=
2
[minv, j]=min(F_val)
minv = j=1
f =
g =
F=f+l*g
F=
Fx=diff(F,x);
Fy=diff(F,y);
Fz=diff(F,z);
[l,u,v,w]=solve(Fx==0,Fy==0,Fz==0,g,[l,x,y,z])
l=
u=
v=
w=
F_val=subs(F,{x,y,z},{u,v,w})
F_val =
[maxv i]=max(F_val)
maxv =
50 i = 5
[minv j]=min(F_val)
minv = j=6
4. DERIVATIVES
%derivative
%Solve the differential equation y’=x if y(0)=0
syms y(x)
ode=diff(y,x)==x
ode(x) =
con=y(0)==0
con =
ysol(x)=dsolve(ode,con)
ysol(x) =
ode(x) =
con=y(0)==1
con =
ysol(x)=dsolve(ode,con)
ysol(x) =
ode(x) =
con=y(0)==2
con =
1
ysol(x)=dsolve(ode,con)
ysol(x) =
ysol(x)=dsolve(ode)
ysol(x) =
clc clear
all syms b
c v(x)
ode = v*diff(v,x) == -c*x - b*v^2
ode(x) =
con=v(0)==0
con =
vsol(x) = dsolve(ode,con)
vsol(x) =
2
%A resistance of 100 ohm, an inductor of 0.5
henry %are connected in series with a battery of
20V.
%find the current in the circuit at t=0.5 sec,if i=0
%at t=0
syms i(t)
R=100;L=0.5;V=20; ode =
L*diff(i,t)==(V-i*R)
ode(t) =
con=i(0)==0
con =
isol(t) = dsolve(ode,con)
isol(t) =
3
5. VIEW SOLID PROBLEMS
4
%Find the volume of the region D enclosed by the surfaces z=x^2 + 3y^2 and
%z= 8 - x^2 - y^2
z1 =
z2 = 8 - x^2 - y^2
z2 =
ry = solve(z1-z2,y)
ry =
ylim1 = ry(1)
ylim1 =
ylim2 = ry(2)
ylim2 =
rx = solve(ry(1),x)
rx =
xlim1 = rx(1)
xlim1 =
5
xlim2 = rx(2)
xlim2 =
volume =
vpaintegral(vpaintegral(vpaintegral(1,z,z1,z2),y,ylim1,ylim2),x,xlim1,xlim2)
volume =
viewSolid(z,z2,z1,y,ylim1,ylim2,x,xlim1,xlim2)
z1 =
6
z2 = 4- x^2 - y^2
z2 =
d = 1 + x
d =
ry = solve(z1-z2,y)
ry =
ylim1 = ry(1)
ylim1 =
ylim2 = ry(2)
ylim2 =
rx = solve(ry(1),x)
rx =
xlim1 = rx(1)
xlim1 =
xlim2 = rx(2)
xlim2 =
volume =
vpaintegral(vpaintegral(vpaintegral(1,z,z1,z2),y,ylim1,ylim2),x,xlim2,xlim1)
volume =
mass =
vpaintegral(vpaintegral(vpaintegral(d,z,z1,z2),y,ylim1,ylim2),x,xlim1,xlim2)
mass =
7
viewSolid(z,z2,z1,y,ylim1,ylim2,x,xlim1,xlim2)
8
9
6.LINE INTEGRALS
10
ind the line integral off (x,y,z) = 2xy +sqrt(z) over the helix r(t) = cos(t) +sin(t) +t , o<t<pi
clc clear
all syms x y
z t
F = 2*x*y + sqrt(z)
F =
DR1 =
NF2 =
I = vpa(int(NF2,t,0,pi))
I =
11
Q2 Evaluate integral of CF.dr , where F(x,y,z) = z*i +xy j -y2 k along the curve C given by r(t) = t^2 i t j
sqrt(t) k , 0< t< 1
clc clear
all syms x y
z t
F = [z x*y -y^2]
F =
C = [t^2; t; sqrt(t)]
C =
DR1 = diff(C,t)
DR1 =
12
F1 = subs(F,[x,y,z,], [C(1), C(2), C(3)]);
DR2 = DR1.*DR1;
NF = sum(DR2); NF1 = sqrt(NF);
NF2 = F1*NF1
NF2 =
I = vpa(int(NF2,t,0,1))
I =
t = 0:1/100:1;
figure;
plot3(t.^2, t, sqrt(t))
grid on
axis square
hold on
p = inline(vectorize(F(1)),'x','y','z')
p =
Inline function:
p(x,y,z) = z
q = inline(vectorize(F(2)),'x','y','z')
q =
Inline function:
q(x,y,z) = x.*y
r = inline(vectorize(F(3)),'x','y','z')
r =
Inline function:
r(x,y,z) = -y.^2
x = linspace(0,2*pi,10);
y =x
y = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
13
z =x
z = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
[x,y,z] = meshgrid(x,y,z);
u = p(x,y,z);
v = q(x,y,z);
w = r(x,y,z);
quiver3(x,y,z,u,v,w,1.5)
Find the mass of a thin wire lying along the curve r(t) = sqrt(2t) + sqrt(2t) + (4-t^2) 0<t<1 , if the density
is 3t
clc clear
all syms x y
z t F = 3*t
F =
T = [sqrt(2).*t;sqrt(2).*t;(4-t^2)]
T =
14
DR1 = diff(T,t)
DR1 =
F1 = subs(F,[x,y,z],[T(1),T(2),T(3)])
F1 =
DR2 = DR1.*DR1
DR2 =
NF = sum(DR2)
NF =
NF1 = sqrt(NF)
NF1 =
NF2 = F1.*NF1
NF2 =
I= vpa(int(NF2,t,0,1))
I =
t = 0:1/50:1
t = 1×51
0 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400
15
figure plot3(sqrt(2).*t,sqrt(2).*t,(4-t.^2))
grid on
axis square
FInd the circulation of the field F = (x-y)i+xj around the circle r(t) = cos(t)i +sin(t) j , 0<t<1
clc clear
all syms x
y t
F = [(x-y) x]
F =
C = [cos(t) sin(t)]
C =
DR1 = diff(C,t)
DR1 =
F1 = subs(F,[x,y,],[C(1),C(2)]);
DR2 = DR1.*DR1
DR2 =
16
NF = sum(DR2);
NF1 = sqrt(NF);
NF2 = F1*NF1;
I = vpa(int(NF2,t,0,1))
I =
t = 0:1/100:2*pi
t = 1×629
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
figure
plot(cos(t),sin(t))
grid on
axis square
hold on
p = inline(vectorize(F(1)),'x','y')
p =
Inline function:
p(x,y) = x - y
q = inline(vectorize(F(2)),'x','y')
q =
Inline function:
q(x,y) = x
x = linspace(0,2*pi,10)
x = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
y =x
y = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
[x,y] = meshgrid(x,y);
u = p(x,y); v =
q(x,y);
quiver(x,y,u,v)
17
find the flux of F = (x-y)i+xj across the circle x2 + y2 = 1 in the xy plane
clc clear
all syms x
y t
F = [(x-y) x]
F =
C = [x^2 y^2]
C =
DR1 = diff(C,t)
DR1 =
F1 = subs(F,[x,y,],[C(1),C(2)]);
DR2 = DR1.*DR1
DR2 =
18
I =
t = 0:1/100:2*pi
t = 1×629
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700
figure
plot(cos(t),sin(t))
grid on
axis square
hold on
p = inline(vectorize(F(1)),'x','y')
p =
Inline function:
p(x,y) = x - y
q = inline(vectorize(F(2)),'x','y')
q =
Inline function:
q(x,y) = x
x = linspace(0,2*pi,10)
x = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
y =x
y = 1×10
0 0.6981 1.3963 2.0944 2.7925 3.4907 4.1888 4.8869
[x,y] = meshgrid(x,y);
u = p(x,y); v =
q(x,y);
quiver(x,y,u,v)
19
20