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

EXPERIMENT 1

INPUT-
clc
clear all
rv=[1 2 3 4 5] %row vector
cv=rv' %'-transpose
cv2=[1;2;3;4;5] %column vector
lrv=length(rv);
srv=size(rv);
A=[1 2 3;4 5 6;7 8 9]
dA=det(A)
rA=rank(A)
lA=tril(A)
uA=triu(A)
gA=diag(A)
B=[7 8 9;1 3 4;5 6 2]
C=A+B
D1=A*B %MATRIX MULTIPLICATION
D2=A.*B %CMOPONENT WISE MULTIPLICATION
E=inv(A) %INVERSE OF MATRIX A
size(A)
A(2,:)=[]
size(A)

OUTPUT-
rv =

1 2 3 4 5

cv =

3
4

cv2 =

A=

1 2 3

4 5 6

7 8 9

dA =

6.6613e-16
rA =

lA =

1 0 0

4 5 0

7 8 9

uA =

1 2 3

0 5 6

0 0 9

gA =

5
9

B=

7 8 9

1 3 4

5 6 2

C=

8 10 12

5 8 10

12 14 11

D1 =

24 32 23

63 83 68

102 134 113


D2 =

7 16 27

4 15 24

35 48 18

Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =

1.541976e-18.

> In ABC (line 18)

E=

1.0e+16 *

-0.4504 0.9007 -0.4504

0.9007 -1.8014 0.9007

-0.4504 0.9007 -0.4504

ans =

3 3
A=

1 2 3

7 8 9

ans =

2 3
Experiment 2
Input
%lab 2
%Title: PLOTTING OF CURVES AND SURFACES
%1. Parametric plot
clc
clear all
t=linspace(0,2*pi,20);
x=3+2*cos(t);
y=4+2*sin(t);
plot(x,y,'k-*')
axis equal
xlabel('x-Axis')
ylabel('y-Axis')
title('Graph of a circle with Centre(3,4) and Radius 2')
legend('(x-1)^2+(y-3)^2=4')

Output-
Input
%2.MULTIPLE PLOTS IN A FIGURE WINDOW(USNG COMMAND HOLD ON)
clc
clear all
x=linspace(0,1)
plot(x,x.*2,'r*')
hold on
plot(x,sin(x),'g.')
plot(x,exp(x),'m+')
legend('x*2','sin(x)','exp(x)')

Output
Columns 91 through 99

0.9091 0.9192 0.9293 0.9394 0.9495 0.9596 0.9697


0.9798 0.9899

Column 100

1.0000
Input
%exp 4
clc
clear all
x=0:0.1:2*pi;
subplot(2,2,1)
plot(x,sin(x));
subplot(2,2,2)
plot(x,cos(x),'r-*');
subplot(2,2,3)
plot(x,exp(-x),'go')
subplot(2,2,4);
plot(x,sin(3*x),'ms')

output
Columns 28 through 36

0.2727 0.2828 0.2929 0.3030 0.3131 0.3232 0.3333 0.3434 0.3535

Columns 37 through 45

0.3636 0.3737 0.3838 0.3939 0.4040 0.4141 0.4242 0.4343 0.4444

Columns 46 through 54
Input

%3-multiple plots in a figure window(without command hold on)


clc
clear all
x=linspace(0,1)
plot(x,x.^3,'r*',x,sin(x),'k-',x,exp(x),'g.')
legend('x^3','sin(x)','exp(x)')
title('miltiple curves in a figure window')

OUTPUT-
Columns 91 through 99
0.9091 0.9192 0.9293 0.9394 0.9495 0.9596 0.9697 0.9798 0.9899

Column 100

1.0000
Experiment 3

Input

%maxima and minima


clc
clear all

syms x real
f=x^3*(x-5)^2;
fx=diff(f,x);
fxx=diff(fx,x);
c=solve(fx)
c=double(c);
fprintf('There are %d critical points, and are shown
below.',length(c))
fprintf('\n\n')
disp(c(:))

cmin=min(c);cmax=max(c);
D=[cmin-0.2 cmax+0.2]
ezplot(f,D)
hold on
h=ezplot(fx,D)
set(h,'color','r')
e=ezplot(fxx,D)
set(e,'color','g')
legend('f','fx','fxx')

for i=1:length(c)
T1=subs(fxx,x,c(i));T1=double(T1);
T3=subs(f,x,c(i));T3=double(T3);
if(T1==0)
fprintf('\nThe inflection point is x=%d.',c(i))
fprintf('\nTestfails.')
elseif(T1<0)
fprintf('\nMaximum occurs at x=%d.',c(i))
fprintf('\nMaximum value is f(%d)=%d.',c(i),T3)
else
fprintf('\nMinimum point occurs at x=%d',c(i))
fprintf('\nMinimum value isf(%d)=%d.\n',c(i),T3)
end
plot(c(i),T3,'r*','markersize',15);
end
output-
c=

There are 4 critical points, and are shown below.

D=

-0.2000 5.2000

h=

Line with properties:

Color: [0.4660 0.6740 0.1880]


LineStyle: '-'

LineWidth: 0.5000

Marker: 'none'

MarkerSize: 6

MarkerFaceColor: 'none'

XData: [1x434 double]

YData: [1x434 double]

ZData: [1x0 double]

Show all properties

e=

Line with properties:

Color: [0.3010 0.7450 0.9330]

LineStyle: '-'

LineWidth: 0.5000

Marker: 'none'

MarkerSize: 6

MarkerFaceColor: 'none'

XData: [1x434 double]

YData: [1x434 double]

ZData: [1x0 double]

Show all properties


The inflection point is x=0.

Testfails.

The inflection point is x=0.

Testfails.

Maximum occurs at x=3.

Maximum value is f(3)=108.

Minimum point occurs at x=5

Minimum value isf(5)=0.


Experiment 5

Input-
clc
clear
syms x
y1=input('ENTER THE UPPER CURVE AS A FUNCTION OF X:');
y2=input('ENTER THE LOWER CURVE AS A FUNTCION OF X:');

t=solve(y1-y2);t=double(t);
A=int(y1-y2,t(1),t(2))
D=[t(1)-0.2 t(2)+0.2];
ez1=ezplot(y1,D);
set(ez1,'color','r')
hold on
ez2=ezplot(y2,D);
legend('y1','y2')
xv=linspace(t(1),t(2));
y1v=subs(y1,x,xv);
y2v=subs(y2,x,xv);
x=[xv,xv];
y=[y1v,y2v];
fill(x,y,'g')
grid on

OUTPUT-
ENTER THE UPPER CURVE AS A FUNCTION OF X:x

ENTER THE LOWER CURVE AS A FUNTCION OF X:x^2-2*x

A=

9/2
Q1) y=-x^2+4x

y=x^2

ans-ENTER THE UPPER CURVE AS A FUNCTION OF X:-x^2+4*x

ENTER THE LOWER CURVE AS A FUNTCION OF X:x^2

A=

8/3
Q2) y=7-2*x^2

y=x^2+4

ans-ENTER THE UPPER CURVE AS A FUNCTION OF X:7-2*x^2

ENTER THE LOWER CURVE AS A FUNTCION OF X:x^2+4

A=

4
Experiment 6
Input-
clc
clear
syms t s
f=input('enter the function in terms of t:');
F=laplace(f)

OUTPUT-
1 -enter the function in terms of t:sin(t)

F=

1/(s^2 + 1)

2 -enter the function in terms of t:cos(5*t)

F=

s/(s^2 + 25)

3- enter the function in terms of t:sin(a*t)

F=

a/(a^2 + s^2)
heaviside fn
Input-
clc
syms x
g1=x*(heaviside(x-0)-heaviside(x-1));
g2=(2-x)*(heaviside(x-1)-heaviside(x-2));
f=g1+g2;
F=laplace(f)
xv=linspace(0,2,100);
g1v=subs(g1,x,xv);
g2v=subs(g2,x,xv);
fv=subs(f,x,xv);
subplot(3,1,1)
plot(xv,g1v,'r.')
subplot(3,1,2)
plot(xv,g2v,'r.')
subplot(3,1,3)
plot(xv,fv,'r.')

output-

F=

1/s^2 - exp(-s)/s^2 - exp(-s)/s + (exp(-2*s)*(s*exp(s) - exp(s) + 1))/s^2


Experiment 6.2
Input-

clc
syms x
g1=sin(x)*(heaviside(x-0)-heaviside(x-2));
g2=cos(x)*(heaviside(x-2)-heaviside(x-4));
g3=x*(heaviside(x-4)-heaviside(x-6));
f=g1+g2+g3;
F=laplace(f)
xv=linspace(0,2,100);
g1v=subs(g1,x,xv);
g2v=subs(g2,x,xv);
g3v=subs(g3,x,xv);
fv=subs(f,x,xv);
subplot(4,4,1)
plot(xv,g1v,'r.')
subplot(4,4,2)
plot(xv,g2v,'r.')
subplot(4,4,3)
plot(xv,g3v,'r.')
subplot(4,4,4)
plot(xv,fv,'r.')

output-
F=

(4*exp(-4*s))/s + exp(-4*s)/s^2 - (6*exp(-6*s))/s - exp(-6*s)/s^2 + (exp(2*s - 2i)*exp(2*s +


2i)*exp(4*s - 4i)*1i - exp(2*s - 2i)*exp(2*s + 2i)*exp(4*s + 4i)*1i - exp(2*s - 2i)*exp(4*s -
4i)*exp(4*s + 4i)*1i + exp(2*s + 2i)*exp(4*s - 4i)*exp(4*s + 4i)*1i - s*exp(2*s - 2i)*exp(2*s +
2i)*exp(4*s - 4i) - s*exp(2*s - 2i)*exp(2*s + 2i)*exp(4*s + 4i) + s*exp(2*s - 2i)*exp(4*s -
4i)*exp(4*s + 4i) + s*exp(2*s + 2i)*exp(4*s - 4i)*exp(4*s + 4i))/(2*exp(2*s - 2i)*exp(2*s +
2i)*exp(4*s - 4i)*exp(4*s + 4i) + 2*s^2*exp(2*s - 2i)*exp(2*s + 2i)*exp(4*s - 4i)*exp(4*s + 4i)) -
(exp(2*s - 2i) + exp(2*s + 2i) + s*exp(2*s - 2i)*1i - s*exp(2*s + 2i)*1i - 2*exp(2*s - 2i)*exp(2*s +
2i))/(2*exp(2*s - 2i)*exp(2*s + 2i) + 2*s^2*exp(2*s - 2i)*exp(2*s + 2i))
Experiment 6.3
Input-
clc
clear
syms t s
T=input('enter the period of the periodic function:');
n=input('enter the number of partitions in one full period:');
fun=0*t;
for i=1:n
a(i)=input('enter the left end point of the ith interval:');
b(i)=input('enter the right end point of the ith interval:');
f(i)=input('enter the function f(i)of the ith sub interval:');
fun=fun+f(1)*(heaviside(t-a(i))-heaviside(t-b(i)));
end
ezplot(fun,[a(1) b(n)])
sum=0;
for i=1:n
sum=sum+int(f(i)*exp(-s*t),t,a(i),b(i))
end
g=(1/(1-exp(-s*T)))*sum
g1=simplify(g)
figure
ezplot(g1,[0 b(n)])

Output-
enter the period of the periodic function:2

enter the number of partitions in one full period:2

enter the left end point of the ith interval:0

enter the right end point of the ith interval:1

enter the function f(i)of the ith sub interval:2-t

enter the left end point of the ith interval:1

enter the right end point of the ith interval:2

enter the function f(i)of the ith sub interval:t

sum =
(exp(-s)*(s + 1))/s^2 - 1/s^2 - (2*(exp(-s) - 1))/s

sum =

(2*exp(-s)*(s + 1))/s^2 - 1/s^2 - (2*(exp(-s) - 1))/s - (exp(-2*s)*(2*s + 1))/s^2

g=

((2*(exp(-s) - 1))/s + 1/s^2 - (2*exp(-s)*(s + 1))/s^2 + (exp(-2*s)*(2*s + 1))/s^2)/(exp(-2*s) - 1)

g1 =

(2*s - exp(s) + 2*s*exp(s) + 1)/(s^2*(exp(s) + 1))


Experiment 7:
Input-
%limits and continuity
clear

clc
syms x y m n
f=(x^3-y)/(x^3+y);
lp=[0 0];
x0=lp(1);
y0=lp(2);
L1=limit(limit(f,x,x0),y,y0)
L2=limit(limit(f,y,y0),x,x0)
y=m*x^3-x
fx=subs(f);fx=simplify(fx);
L3=limit(fx,x,x0)

output-
L1 =

-1

L2 =

y=

m*x^3 - x

L3 =

-1
Experiment 8
Input-

%partial derevatives- maxima and minima


clear all
clc
syms x y real
f=x^4+y^4-4*x*y+1;
fx=diff(f,x)
fy=diff(f,y)
fxx=diff(fx,x)
fyy=diff(fy,y)
fxy=diff(fx,y)
d=fxx*fyy-(fxy)^2
[cx,cy]=solve(fx,fy)
cx=double(cx);cy=double(cy);
for i=1:length(cx)
T1=subs(subs(d,x,cx(i)),y,cy(i));T1=double(T1);
T2=subs(subs(d,x,cx(i)),y,cy(i));T2=double(T2);
T3=subs(subs(d,x,cx(i)),y,cy(i));T3=double(T3);
if(T1==0)
fprintf('\n second derevative test fails at the point(%d,%d). the
critical point needs further investigation needed.\n',cx(i),cy(i))
elseif(T1<0)
fprintf('\nfunction has a saddle point at(%d,%d).',cx(i),cy(i))
fprintf('\n(%d,%d)=%d\n',cx(i),cy(i),T3)
else
if(T2<0)
fprintf('\n the maximum point is(%d,%d).',cx(i),cy(i))
fprintf('\n maximum value is f(%d,%d)=%d\n',cx(i),cy(i),T3)
else
fprintf('\n f has local minimum at(%d,%d).',cx(i),cy(i))
fprintf('\n minimum value is f(%d,%d)=%d\n',cx(i),cy(i),T3)

end
end
end

Output-
fx = 4*x^3 - 4*y

fy = 4*y^3 - 4*x
fxx = 12*x^2

fyy = 12*y^2

fxy = -4

d = 144*x^2*y^2 - 16

cx =

-1

cy =

-1

1
function has a saddle point at(0,0).

(0,0)=-16

f has local minimum at(-1,-1).

minimum value is f(-1,-1)=128

f has local minimum at(1,1).

minimum value is f(1,1)=128


Experiment 9
Input-
clc
clear all
syms x y real
f=input('enter the function f(x,y):');
fx=diff(f,x);
fy=diff(f,y);
[ax ay]=solve(fx,fy);
fxx=diff(fx,x);
fxy=diff(fx,y);
fyy=diff(fy,y);
D=fxx*fyy- fxy^2;
for i= 1:1:size(ax)
figure
T1=subs(subs(D,x,ax(i)),y,ay(i));
T2=subs(subs(fxx,x,ax(i)),y,ay(i));
T3=subs(subs(f,x,ax(i)),y,ay(i));
if (double(T1)==0)
sprintf('the point (x,y) is (%d,%d) and need further investigation',double(ay(i)))
elseif (double(T1)<0)
sprintf('the point (x,y) is saddle point',double(ax(i)),double(ay(i)))
else
if (double(T2)<0)
sprintf('the maximum point(x,y) is (%d,%d)',double(ax(i)),double(ay(i)))
sprintf('the value of the function is %d',double(T3))
else
sprintf('the maximum point(x,y) is (%d,%d)',double(ax(i)),double(ay(i)))
sprintf('the value of the function is %d',double(T3))
end
end
ezsurf(f,[double(ax(i))-2,double(ax(i))+2,double(ay(i))-2,double(ay(i))+2]);
hold on
plot3(double(ax(i)),double(ay(i)),double(T3),'r*','markersize',15);
end
Output-

enter the function f(x,y):x^4+y^4-4*x*y+1

ans =

the point (x,y) is saddle point

ans =

the maximum point(x,y) is (-1,-1)


ans =

the value of the function is -1

ans =

the maximum point(x,y) is (1,1)

ans =

the value of the function is -1

You might also like