0% found this document useful (0 votes)
68 views

Matlab Codes

This document contains MATLAB code that: 1) Plots various functions including cosine, sine, exponential, and their combinations. 2) Performs Laplace transforms and inverse Laplace transforms of functions. 3) Finds the area between two functions using integration. 4) Identifies and plots inflection points of functions. 5) Plots tangent lines at given points on functions.

Uploaded by

Harsha Vardhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Matlab Codes

This document contains MATLAB code that: 1) Plots various functions including cosine, sine, exponential, and their combinations. 2) Performs Laplace transforms and inverse Laplace transforms of functions. 3) Finds the area between two functions using integration. 4) Identifies and plots inflection points of functions. 5) Plots tangent lines at given points on functions.

Uploaded by

Harsha Vardhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

clc

clear all
x=0:0.1:2*pi;
subplot(2,2,1)
plot(x,cos(x));
subplot(2,2,2)
plot(x,sin(2*x),'r');
subplot(2,2,3)
plot(x,exp(3*x),'g')
subplot(2,2,4)
plot(x,x.*exp(-x),'y')
clc
clear all
syms t
x = 2+t^2;
y = 6 + t*0;
z = 2/(2*t-5);
a = x*(heaviside(t-0)-heaviside(t-2)) + y*(heaviside(t-2)-heaviside(t-3)) + z*(heaviside(t-3)-
heaviside(t-Inf));
laplace(a)

clc
clear all
syms t s
T=input('enter the period of the function:')
n=input('enter the number of partitions:')
fun=0*t
for i=1:1:n
a(i)=input('enter the lower end:')
b(i)=input('enter the upper end:')
f(i)=input('enter the function:')
fun=fun+f(i)*(heaviside(t-a(i))-heaviside(t-b(i)))
end
ezplot(fun,[a(1) b(n)])
sum=0
for i=1: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)

clc
clear all
syms x
f1=input('enter the f(x):')
f2=input('enter the f(x):')
ezplot(f1)
hold on
ezplot(f2)
t=solve(f1-f2)
k=double(t)
x1=linspace(k(1),k(2))
yy1=subs(f1,x,x1);
yy2=subs(f2,x,x1);
x1=[x1,fliplr(x1)];
yy=[yy1,fliplr(yy2)];
fill(x1,yy,'g')
grid on
clc
clear all
syms x
d=[-pi/4,pi/4]
ezplot(sin(4*x),d)
hold on
ezplot(exp(4*x),d)
clc
clear all
syms t s
T=input('enter the period of the function:')
n=input('enter the number of partitions:')
fun=0*t
for i=1:1:n
a(i)=input('enter the lower end:')
b(i)=input('enter the upper end:')
f(i)=input('enter the function:')
fun=fun+f(i)*(heaviside(t-a(i))-heaviside(t-b(i)))
end
ezplot(fun,[a(1) b(n)])
sum=0
for i=1: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)

clc
clear all
x=0:0.001:2*pi
y=cos(x)
z=cos(2*x)
t=cos(3*x)
plot(x,y,'r^',x,z,'go',x,t,'b*')
clc
clear all
syms x
d=[-pi,pi]
ezplot(sin(3*x),d)
hold on
ezplot(exp(x),d)
hold on
ezplot(cos(3*x),d)
hold on
ezplot(x^2,d)

clc
clear all
syms x
f=input('enter the f(x):')
ezplot(f,[0,3])

clc
clear all
syms x y
z=x.^3+y.^3+2*(x.^2)*y;
x1=1;
y1=2;
z1=subs(subs(z,x,x1),x,x1);
ezsurf(z,[x1-2 x1+2])
slopex=subs(subs(diff(z,x),x,x1),y,y1);

clc
clear all
x=0:0.1:2*pi;
subplot(2,2,1)
plot(sin(x));
subplot(2,2,2)
plot(cos(x));
subplot(2,2,3)
plot(exp(-x));
subplot(2,2,4)
plot(sin(3*x));

clc
clear all
t=linspace(0,2*pi);
x=4+2*cos(t);
y=5+2*sin(t);
plot(x,y);
axis equal
title('graph of (x-4)^2+(y-5)^2=4')
legend('(x-3)^2+(y-4)^2=4')

clc
clear all
t=linspace(0,2*pi,500);
x=sin(t);y=sin(6*t);
z=cos(5*t);
comet(x,y)
plot3(x,y,z)
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')

clc
clear all
syms t a s
for i=1:1:5
f=input('enter the f(t):')
F=laplace(f)
end
clc
clear all
syms s a t
f=input('enter the function:')
F=ilaplace(f)
clc
clear all
syms x real
f=input('enter the f(x):');
fx=diff(f,x)
c=solve(fx,x);
cmin=min(double(c))
cmax=max(double(c))
ezplot(f,[cmin-2,cmax+2])
hold on
fxx=diff(fx,x);
for i=1:1:size(c)
T1=subs(fxx,x,c(i))
T3=subs(f,x,c(i))
if(double(T1)==0)
sprintf('the point x is %d inflexion point',double(c(i)))
else
if(double(T1)<0)
plot(double(c(i)),double(T3),'r+','markersize',15)
else
if(double(T1>0))
plot(double(c(i)),double(T3),'r+','markersize',15)
end
end
end
end

clc
clear all
syms x
f1=input('enter the f(x):')
f2=input('enter the f(x):')
ezplot(f1)
hold on
ezplot(f2)
t=solve(f1-f2)
f=int((f1)-(f2),t(1),t(2))
k=double(t)
x1=linspace(k(1),k(2))
yy1=subs(f1,x,x1);
yy2=subs(f2,x,x1);
x1=[x1,fliplr(x1)];
yy=[yy1,fliplr(yy2)];
fill(x1,yy,'g')
grid on
f=int((f1-f2),t(1),t(2))

clc
clear all
syms x
f1=input('enter the f(x):')
f2=input('enter the f(x):')
ezplot(f1)
hold on
ezplot(f2)
t=solve(f1-f2)
k=double(t)
x1=linspace(k(1),k(2))
yy1=subs(f1,x,x1);
yy2=subs(f2,x,x1);
x1=[x1,fliplr(x1)];
yy=[yy1,fliplr(yy2)];
fill(x1,yy,'g')
grid on
f=int((f1-f2),t(1),t(2))

clc
clear all
syms x
f=input('enter the f(x):')
x1=2
ezplot(f,[x1-2,x1+2])
hold on
f1=diff(f,x);
m=subs(f1,x,x1)
y1=subs(f,x,x1)
plot(x1,y1,'b*')
tgt_line=m*(x-x1)+y1
ezplot(tgt_line,[x1-2,x1+2]);

You might also like