0% found this document useful (0 votes)
16 views17 pages

Matlab 1

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

Matlab 1

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

NAME:MAMIDI GIRI NAGA VENKATA RANGA

PRANEETH

COURSE CODE:MAT1001
COURSE NAME:CALCULUS FOR ENGINEERS-
EMBEDDED LAB

SLOT:L20+L21

REGD N0.:23BCE9683

NAME OF INSTRUCTOR:KOTTALA PANDURANGA


%-----------MAMIDI GIRI NAGA VENKATA RANGA PRANEETH------------------------
%-----------REGD NO.:23BCE9683-------ASSIGNMENT----------------------------

clc
clear all
LAB-1
1)
syms x
v=x*(12-2*x)^2;
dv=diff(v,x)
roots=solve(dv==0)
ddv=diff(dv,x)
for i=1:length(roots)
fv=subs(ddv,roots(i));
if fv<0
max=subs(v,roots(i))
end
end
output:
dv = x*(8*x - 48) + (2*x - 12)^2
roots = 2 6
ddv = 24*x - 96
max = 128
2)
syms x y

a=75;
a=x*y;
%c=4*x+8*x+8*y+8*y
c=12*x+1200/x;
dc=diff(c,x)
solutions=solve(dc==0)
ddc=diff(dc,x)
for i=1:length(solutions)
ac=subs(ddc,solutions(i))
if ac<0
continue
else ac>0
x_val=solutions(i)
end
end
y=double(75/x_val)
Output:

dc = 12 - 1200/x^2

solutions = -10 10

ddc = 2400/x^3

ac = -12/5

ac = 12/5

ans = 0 < 12/5

x_val = 10

y = 7.5000
3)
v=100;
syms r h
a=2*pi*r*(100/(pi*r^2))+2*pi*r^2;
da=diff(a,r)
root=double(solve(da==0))
dda=diff(da,r)
for i=1:length(root)
if root(i)>0
r=double(root(i))
end
end
h=100/(pi*r^2)
Output:

da = 4*pi*r - 200/r^2

root =

2.5154 + 0.0000i

-1.2577 + 2.1784i

-1.2577 - 2.1784i

dda = 4*pi + 400/r^3

r = 2.5154

h = 5.0308

4)
% T=Tswim+Trun=>velocity=distance/time
% Tswim=y/5=>Trun=100-x/15,x^2+(50)^2=y^2
syms x
T=1/5*(x^2+2500)^(0.5)+1/15*(100-x);
dt=diff(T,x)
sol=double(solve(dt==0))
Output:

dt = x/(5*(x^2 + 2500)^(1/2)) - 1/15

sol = 17.6777
LAB-2

5)
syms x
a1=int(x-x^2,0,1)
a2=abs(int(x-x^2,1,1.5))
a=a1+a2
output:

a1 = 1/6

a2 = 1/6

a = 1/3
syms x
a1=abs(int(x^2-x,0,1))
a2=abs(int(x^2-x,1,2))
a=a1+a2
output:
a1 = 1/6

a2 = 5/6

a=1
syms x
a1=abs(int(x^3-3*x,-1,0))
a2=abs(int(x^3-3*x,0,1))
a=a1+a2
output:
a1 = 5/4

a2 = 5/4

a = 5/2
syms x b
a1=int(-2*(exp(3*x)),0,b)
output:
a1 = 2/3 - (2*exp(3*b))/3

6)
x=1:1:3

f=x.^4-3*x.^3-4*x.^2+10
g=40-x.^2
plot(f,x)
hold on
plot(g,x)
legend("f=x^4-3*x^3-4*x^2+10","g=40-x^2")
syms x
f=x^4-3*x^3-4*x^2+10;
g=40-x^2;
a=int(g-f,x,1,3)
output:
x=1 2 3
f = 4 -14 -26

g = 39 36 31
a = 488/5

7)

a)

t=0:0.1:3
E=2*t.^2
C=9+t.^2
plot(E,t)
hold on
plot(C,t)
legend("E=2*t^2","C=9+t^2")

output:
b)
syms t
solve(2*t^2==9+t^2)
output:

ans = -3 3

c)
syms t
e=2*t^2;
c=9+t^2;
a=abs(int(e-c,t,0,3)
output:

a = 18
LAB-3

8)
syms x y
f=2*x^3+6*x*y^2-3*y^3-150*x;
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
H=hessian(f)
DD=det(H)
[x_val,y_val]=solve(fx==0,fy==0)
c=[x_val(:),y_val(:)]
for i=1:length(c)
fxx1=subs(fxx,{x,y},{x_val(i),y_val(i)});
D=subs(DD,{x,y},{x_val(i),y_val(i)});
if D<0
fprintf('f has saddle point at (%0.4f,%0.4f)',x_val(i),y_val(i))
elseif D>0 && fxx1<0
v=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local maximum at(%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),v)
elseif D>0 && fxx1>0
a=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local minimum at (%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),a)
else
fprintf('Test fails at (%0.4f,%0.4f)',x_val(i),y_val(i))
end
end

output:

fx = 6*x^2 + 6*y^2 - 150

fy = - 9*y^2 + 12*x*y

fxx = 12*x

fxy = 12*y

fyy = 12*x - 18*y

H=

[12*x, 12*y]

[12*y, 12*x - 18*y]

DD = 144*x^2 - 216*x*y - 144*y^2

x_val =

-5

-3
3

y_val =

-4

c=

[-5, 0]

[ 5, 0]

[-3, -4]

[ 3, 4]

f has local maximum at(-5.0000,0.0000)=500.0000

f has local minimum at (5.0000,0.0000)=-500.0000

f has saddle point at (-3.0000,-4.0000)

f has saddle point at (3.0000,4.0000)

9)
syms x y
f=x^3+y^3-3*x-12*y+20;
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
H=hessian(f)
DD=det(H)
[x_val,y_val]=solve(fx==0,fy==0)
c=[x_val(:),y_val(:)]
for i=1:length(c)
fxx1=subs(fxx,{x,y},{x_val(i),y_val(i)});
D=subs(DD,{x,y},{x_val(i),y_val(i)});
if D<0
fprintf('f has saddle point at (%0.4f,%0.4f)',x_val(i),y_val(i))
elseif D>0 && fxx1<0
v=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local maximum at(%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),v)
elseif D>0 && fxx1>0
a=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local minimum at (%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),a)
else
fprintf('Test fails at (%0.4f,%0.4f)',x_val(i),y_val(i))
end
end
Output:
fx = 3*x^2 - 3

fy = 3*y^2 - 12

fxx = 6*x

fxy = 0

fyy = 6*y

H=

[6*x, 0]

[ 0, 6*y]

DD = 36*x*y

x_val =

-1

-1

y_val =

-2

-2

c=

[-1, -2]

[ 1, -2]

[-1, 2]

[ 1, 2]

f has local maximum at(-1.0000,-2.0000)=38.0000

f has saddle point at (1.0000,-2.0000)

f has saddle point at (-1.0000,2.0000)

f has local minimum at (1.0000,2.0000)=2.0000

10)
syms x y
f=x^3*y^2*(1-x-y);
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
H=hessian(f)
DD=det(H)
[x_val,y_val]=solve(fx==0,fy==0)
c=[x_val(:),y_val(:)]
for i=1:length(c)
fxx1=subs(fxx,{x,y},{x_val(i),y_val(i)});
D=subs(DD,{x,y},{x_val(i),y_val(i)});
if D<0
fprintf('f has saddle point at (%0.4f,%0.4f)',x_val(i),y_val(i))
elseif D>0 && fxx1<0
v=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local maximum at(%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),v)
elseif D>0 && fxx1>0
a=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local minimum at (%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),a)
else
fprintf('Test fails at (%0.4f,%0.4f)',x_val(i),y_val(i))
end
end
Output:

fx = - x^3*y^2 - 3*x^2*y^2*(x + y - 1)

fy = - x^3*y^2 - 2*x^3*y*(x + y - 1)

fxx = - 6*x^2*y^2 - 6*x*y^2*(x + y - 1)

fxy = - 3*x^2*y^2 - 2*x^3*y - 6*x^2*y*(x + y - 1)

fyy = - 2*x^3*(x + y - 1) - 4*x^3*y

H=

[ - 6*x^2*y^2 - 6*x*y^2*(x + y - 1), - 3*x^2*y^2 - 2*x^3*y - 6*x^2*y*(x + y - 1)]

[- 3*x^2*y^2 - 2*x^3*y - 6*x^2*y*(x + y - 1), - 2*x^3*(x + y - 1) - 4*x^3*y]

DD = - 40*x^6*y^2 - 60*x^5*y^3 + 60*x^5*y^2 - 45*x^4*y^4 + 60*x^4*y^3 - 24*x^4*y^2

x_val =

1/2

y_val =

1/3

c=

[1/2, 1/3]

[ 0, 0]f has local maximum at(0.5000,0.3333)=0.0023Test fails at (0.0000,0.0000)


LAB-4

11)
syms x y z lambda
f=x^2+y^2+z^2;
g=1/x+1/y+1/z-1;
H=f+lambda*g
Hx=diff(H,x)
Hy=diff(H,y)
Hz=diff(H,z)
Hlambda=diff(H,lambda)
system=[Hx,Hy,Hz,Hlambda]
[x_val,y_val,z_val,lambda_val]=solve(system,[x y z lambda])
disp('The critical points are')
c=[x_val(:),y_val(:),z_val(:)]
D=subs(f,{x,y,z},{x_val,y_val,z_val})
minf=double(min(D))
output:

H = lambda*(1/x + 1/y + 1/z - 1) + x^2 + y^2 + z^2

Hx = 2*x - lambda/x^2

Hy = 2*y - lambda/y^2

Hz = 2*z - lambda/z^2

Hlambda = 1/x + 1/y + 1/z - 1

system = [2*x - lambda/x^2, 2*y - lambda/y^2, 2*z - lambda/z^2, 1/x + 1/y + 1/z - 1]

x_val =

3/2 - (3^(1/2)*1i)/2

(3^(1/2)*1i)/2 + 3/2

(3^(1/2)*1i)/4 + (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4

(3^(1/2)*1i)/4 - (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4

3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4

3/4 - (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4

y_val =

3/2 - (3^(1/2)*1i)/2

(3^(1/2)*1i)/2 + 3/2

(3^(1/2)*1i)/4 - (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4

(3^(1/2)*1i)/4 + (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4

3/4 - (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4


3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4

z_val =

3^(1/2)*1i

-3^(1/2)*1i

3/2 - (3^(1/2)*1i)/2

3/2 - (3^(1/2)*1i)/2

(3^(1/2)*1i)/2 + 3/2

(3^(1/2)*1i)/2 + 3/2

lambda_val =

54

-3^(1/2)*6i

3^(1/2)*6i

-3^(1/2)*6i

-3^(1/2)*6i

3^(1/2)*6i

3^(1/2)*6i

The critical points are

c=

[ 3, 3, 3]

[ 3/2 - (3^(1/2)*1i)/2, 3/2 - (3^(1/2)*1i)/2, 3^(1/2)*1i]

[ (3^(1/2)*1i)/2 + 3/2, (3^(1/2)*1i)/2 + 3/2, -3^(1/2)*1i]

[(3^(1/2)*1i)/4 + (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4, (3^(1/2)*1i)/4 - (- 648 -


3^(1/2)*648i)^(1/2)/24 + 3/4, 3/2 - (3^(1/2)*1i)/2]

[(3^(1/2)*1i)/4 - (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4, (3^(1/2)*1i)/4 + (- 648 -


3^(1/2)*648i)^(1/2)/24 + 3/4, 3/2 - (3^(1/2)*1i)/2]

[3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4, 3/4 - (- 648 + 3^(1/2)*648i)^(1/2)/24 -


(3^(1/2)*1i)/4, (3^(1/2)*1i)/2 + 3/2]

[3/4 - (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4, 3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 -


(3^(1/2)*1i)/4, (3^(1/2)*1i)/2 + 3/2]

D=

27
2*((3^(1/2)*1i)/2 - 3/2)^2 - 3

2*((3^(1/2)*1i)/2 + 3/2)^2 - 3

((3^(1/2)*1i)/4 - (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4)^2 + ((3^(1/2)*1i)/4 + (- 648 -


3^(1/2)*648i)^(1/2)/24 + 3/4)^2 + ((3^(1/2)*1i)/2 - 3/2)^2

((3^(1/2)*1i)/4 - (- 648 - 3^(1/2)*648i)^(1/2)/24 + 3/4)^2 + ((3^(1/2)*1i)/4 + (- 648 -


3^(1/2)*648i)^(1/2)/24 + 3/4)^2 + ((3^(1/2)*1i)/2 - 3/2)^2

(3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4)^2 + ((3^(1/2)*1i)/4 + (- 648 +


3^(1/2)*648i)^(1/2)/24 - 3/4)^2 + ((3^(1/2)*1i)/2 + 3/2)^2

(3/4 + (- 648 + 3^(1/2)*648i)^(1/2)/24 - (3^(1/2)*1i)/4)^2 + ((3^(1/2)*1i)/4 + (- 648 +


3^(1/2)*648i)^(1/2)/24 - 3/4)^2 + ((3^(1/2)*1i)/2 + 3/2)^2

minf = 0.0000 - 5.1962i


12)
%Let x ft ,y ft and z ft be dimensions of box let s be surface area
%given volume=x*y*z=32 s=2*x*y+2*y*z+z*x=>z=32/x*y
syms y x
f=(64/x)+(64/y)+x*y;
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fxy=diff(fx,y)
fyy=diff(fy,y)
H=hessian(f)
DD=det(H)
[x_val,y_val]=solve(fx==0,fy==0)
c=[x_val(:),y_val(:)]
for i=1:length(c)
fxx1=subs(fxx,{x,y},{x_val(i),y_val(i)});
D=subs(DD,{x,y},{x_val(i),y_val(i)});
if D>0 && fxx1>0
a=subs(f,{x,y},{x_val(i),y_val(i)});
fprintf('f has local minimum at (%0.4f,%0.4f)=%0.4f',x_val(i),y_val(i),a)
x=x_val(i)
y=y_val(i)
z=32/(x*y)
else
fprintf('Test fails at (%0.4f,%0.4f)',x_val(i),y_val(i))
end
end
output:

fx = y - 64/x^2

fy = x - 64/y^2

fxx = 128/x^3

fxy = 1

fyy = 128/y^3

H=
[128/x^3, 1]

[ 1, 128/y^3]

DD = -(x^3*y^3 - 16384)/(x^3*y^3)

x_val =

- 2 - 3^(1/2)*2i

- 2 + 3^(1/2)*2i

y_val =

- 2 - 3^(1/2)*2i

- 2 + 3^(1/2)*2i

c=

[ 4, 4]

[- 2 - 3^(1/2)*2i, - 2 - 3^(1/2)*2i]

[- 2 + 3^(1/2)*2i, - 2 + 3^(1/2)*2i]

f has local minimum at (4.0000,4.0000)=48.0000

x=4

y=4

z=2

13)
syms x y z lambda
u = 400*x*y*z^2
g = x^2+y^2+z^2-1
H = u+lambda*g
Hx = diff(H,x)==0
Hy = diff(H,y)==0
Hz = diff(H,z)==0
Hlambda = diff(H,lambda)==0
system = [Hx Hy Hz Hlambda]
[x_val,y_val,z_val,lambda_val] = solve(system,[x y z lambda])
disp('critical points are')
c = [x_val(:),y_val(:),z_val(:)]
d = subs(u,{x,y,z},{x_val,y_val,z_val})
minu = min(d)
maxu = max(d)
output:
H = lambda*(x^2 + y^2 + z^2 - 1) + 400*x*y*z^2
Hx = 400*y*z^2 + 2*lambda*x == 0
Hy = 400*x*z^2 + 2*lambda*y == 0
Hz = 2*lambda*z + 800*x*y*z == 0
Hlambda = x^2 + y^2 + z^2 - 1 == 0
system =

[400*y*z^2 + 2*lambda*x == 0, 400*x*z^2 + 2*lambda*y == 0, 2*lambda*z + 800*x*y*z


== 0, x^2 + y^2 + z^2 - 1 == 0]
x_val =
-1
1
0
0
0
0
-1/2
1/2
-1/2
1/2
1/2
-1/2
1/2
-1/2
y_val =
0
0
-1
1
0
0
-1/2
1/2
-1/2
1/2
-1/2
1/2
-1/2
1/2
z_val =
0
0
0
0
-1
1
-2^(1/2)/2
-2^(1/2)/2
2^(1/2)/2
2^(1/2)/2
-2^(1/2)/2
-2^(1/2)/2
2^(1/2)/2
2^(1/2)/2
lambda_val =
0
0
0
0
0
0
-100
-100
-100
-100
100
100
100
100
critical points are
c =
[ -1, 0, 0]
[ 1, 0, 0]
[ 0, -1, 0]
[ 0, 1, 0]
[ 0, 0, -1]
[ 0, 0, 1]
[-1/2, -1/2, -2^(1/2)/2]
[ 1/2, 1/2, -2^(1/2)/2]
[-1/2, -1/2, 2^(1/2)/2]
[ 1/2, 1/2, 2^(1/2)/2]
[ 1/2, -1/2, -2^(1/2)/2]
[-1/2, 1/2, -2^(1/2)/2]
[ 1/2, -1/2, 2^(1/2)/2]
[-1/2, 1/2, 2^(1/2)/2]
d =
0
0
0
0
0
0
50
50
50
50
-50
-50
-50
-50
minu = -50
maxu = 50
LAB-5

14)
syms r theta
%z=3-x-y
%x^2+y^2=r^2=>x=rcos(theta),y=rsin(theta)
z=3-r*cos(theta)-r*sin(theta);
innerint=int(z*r,theta,0,2*pi)
outerint=int(innerint,r,0,1)
output:

innerint = 6*pi*r

outerint = 3*pi

15)
syms x y
f=x*y*(x+y);
innerint=int(f,x,y,y^(0.5))
outerint=int(innerint,y,0,1)
output:

innerint = y^3/2 - (5*y^4)/6 + y^(5/2)/3

outerint = 3/56

16)
syms r theta
innerint=int(r^3,r,0,cos(theta))
outerint=int(innerint,theta,0,2*pi)
output:

innerint = cos(theta)^4/4

outerint = (3*pi)/16

17)
syms theta r
innerint=int(r^2*exp(3)*cos(theta)*sin(theta),r,0,1)
outerint=int(innerint,theta,0,2*pi)
output:

innerint = (2826788018837635*sin(2*theta))/844424930131968

outerint = 0

You might also like