You are on page 1of 17

1.

Circle

clc
clear all
t=linspace(0,2*pi,100);
x=1+2*cos(t);
y=3+2*sin(t);
plot(x,y);

output

2.Circle
clc
clear all
t=linspace(0,2*pi,100);
x=1+2*cos(t);
y=3+2*sin(t);
plot(x,y)
axis equal
3.
clc
clear all
x=linspace(0,1,101);
plot(x,x.^3,'r+',x,sin(x),'b*',x,exp(x),'g^');

4.
clc
clear all
x=linspace(0,1,101);
plot(x,x.^3,'r');
hold on
plot(x,sin(x),'g');
hold on
plot(x,exp(x),'m');
hold off
5.
clc
clear all
x=0:0.1:2*pi;
subplot(1,3,1);
plot(x,x.^3);
subplot(1,3,2);
plot(x,sin(x));
subplot(1,3,3);
plot(x,exp(x));

6.
clc
clear all
A=[4 5;7 8];
B=[7;21];
X=A\B

Output

X=

16.3333

-11.6667

7.
clc
clear all
solve('x^3-5*x^2+5*x-25')
ans =

-5^(1/2)*1i

5^(1/2)*1i

8.
clc
clear all
syms x y
f=3*x^2+4*y^5
diff (diff(f,x),y)

output

f=

3*x^2 + 4*y^5

ans =

9.
clc
clear all
syms x
f=cos(x)
int(f)

output
f=

cos(x)

ans =

sin(x)

10.

clc
clear all
syms x
f=cos(x)
int(f,x,0,pi)

output

f = cos(x)

ans = 0

11.

clc
clear all
x=linspace (-pi,pi,100);
f=sin(2*x)-cos(3*x);
plot(x,f)

output

12.

clc
clear all
syms x
f=sin(2*x)-cos(3*x);
ezplot(x,f,[0,pi])
title('MATLAB')
xlabel('yolo')
ylabel('hhiii')

output
13.
syms x real
f=input('Enter the function f(x): ');
fx=diff(f,x)
c=solve(fx)
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)
sprintf('The maximum point x is %d ',double(c(i)))
sprintf('The value of the function is %d ',double(T3))
end
end
plot(double(c(i)),double(T3),'r*','markersize',15);
end
hold off

output

Enter the function f(x): x^2

fx = 2*x

c = 0
14.
clc
clear all
x=0:0.1:2*pi;
subplot(1,3,1);
plot(x,x.^3);
subplot(1,3,2);
plot(x,sin(x));
subplot(1,3,3);
plot(x,exp(x));
legend('x^x3','sin(x)','exp(x)','Northeast')

output

15.
clc
clear all
t=linspace(0,2*pi,500);
x=cos(t);
y=sin(t);
z=sin(5*t);
comet3(x,y,z)
plot3(x,y,z,'r*','markersize',7)
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
title('3D CURVE')

output
16.
clc
clear all
syms x y
f=2*(x^2+y^2)
ezsurf(f)

Output
f =2*x^2 + 2*y^2

17.
clc
clear all
syms x y
f=2*(x^2+y^2)
ezsurf(f)
colormap spring

output

18.
clc
clear all
syms x y
f=2*(x^2+y^2)
ezsurf(f)
colormap spring
shading flat

output
f = 2*x^2 + 2*y^2

19.
clc
clear all
clc
clear all
syms x
y=x^2+2*x-6
ezplot(y)

output
y = x^2 + 2*x – 6
20.
clc
clear all
x=-1:.05:1;
y=x;
[x,y]=meshgrid(x,y);
z=x.*y.^2-x.^3
surf(x,y,z);
colormap cool
shading interp

21.
clc
clear all
syms x
y=input('enter the function f in terms of x:')
x1=input('enter x value at which tangent :')
ezplot(y,[x1-2 x1+2])
hold on
y_derivative=diff(y,x);
slope=subs(y_derivative,x,x1);
y1=subs(y,x,x1);
plot(x1,y1,'r*')
tgt_line=slope*(x-x1)+y1
h=ezplot(tgt_line,[x1-1 x1+1])
set(h,'color','r')
hold off

Output
enter the function f in terms of x:x^2+3*x

y =

x^2 + 3*x

enter x value at which tangent :1

x1 =

1
tgt_line =

5*x - 1

22.
clc
clear all
syms x real
f=input('enter the function f(x):');
fx=diff(f,x)
c=solve(fx)
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)
sprintf('The max point x is %d',double(c(i)))
plot(double(c(i)),double(T3),'g*','markersize',15);
sprintf('the value of the function is %d',double(T3))

else
sprintf('The min point x is %d',double(c(i)))
plot(double(c(i)),double(T3),'r*','markersize',15);
sprintf('the value of the function is %d',double(T3))
end
end
end
hold off

Output
enter the function f(x):x^2+6*x+3

fx = 2*x + 6

c = -3

ans = The min point x is -3

ans = the value of the function is -6

23.
clc
clear all
syms x
f=input('enter the function f(x):');
a=input('enter the lower limit of x:');
b=input('enter the upper limit of x:');
n=input('number of partitions of the domain [a,b]:');
j=int(f,a,b)
j1=int(abs(f),a,b)
dx=(b-a)/n;
xp=a:dx:b;
fxp=subs(f,x,xp);
sn=sum(fxp*dx)
sna=(abs(fxp)*dx)
rsums(f,[a b])
hold on
h=ezplot(f,[a b]);
set(h,'color','r')

output
enter the function f(x):x^2+3*x+6
enter the lower limit of x:0
enter the upper limit of x:2
number of partitions of the domain [a,b]:4

j =
62/3

j1 =

62/3

sn =

105/4

sna =

[ 3, 31/8, 5, 51/8, 8]

24.
clc
clear all
syms x
f=input('enter the function f(x):');
a=input('enter the lower limit of x:');
b=input('enter the upper limit of x:');
n=input('number of partitions of the domain [a,b]:');
j=int(f,a,b)
dx=(b-a)/n;
sum=0
for i=1:n
p=a+i*dx
fp=subs(f,x,p)
sum=sum+fp
end
rs=sum*dx
ezplot(f,[a,b]);
rsums(f,a,b);

Output
enter the function f(x):x^2+5*x+3
enter the lower limit of x:0
enter the upper limit of x:2
number of partitions of the domain [a,b]:4

j =

56/3

sum =

p =

0.5000

fp =

23/4

sum =

23/4

p =

1
fp =

sum =

59/4

p =

1.5000

fp =

51/4

sum =

55/2

p =

fp =

17

sum =

89/2

rs =

89/4
25.
clc
clear all
syms x
y1=input('Enter the upper curve as a function of x:');
y2=input('Enter the lower curve as a function 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);
set(ez2,'color','b')
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

You might also like