You are on page 1of 7

CALCULATOR

clc;
clear all;
command=input('Give the method to be performed','s');
a=input('give the value of a');
b=input('give the value of b');
switch command
case('add')
c=a+b;
case('sub')
c=a-b;
case('mult')
c=a*b;
case('div')
c=a/b;
otherwise
disp('unknown operation')
end
disp(c)
CALCULATOR FUNCTION
function[c]=calcfn(command,a,b)
switch command
case('add')
c=a+b;
case('sub')
c=a-b;
case('mult')
c=a*b;
case('div')
c=a/b;
otherwise
disp('unknown operation')
end
CIRCLE FNC
function[] = circlefn(r)
%in square brackets basically states the
variables in which we want output,in this case they can be blank also
ang=0:0.0001:2*pi;
x=r*cos(ang);
y=r*sin(ang);
plot(x,y,'g*');
axis equal;
%inorder to make both the axis equal and get a perfect circle

FACT

a=input('give value to a=');


fact=1;
for i=1:a
fact= fact*i;
end
disp(fact)

FIBO

clc
clear all
a=1;

b=1;
disp(a)
disp(b)
for i=1:10
c=a+b;
if(c<10)
disp(c)
end
a=b;
b=c;
end
FUNCTION
clc;
clear all;
t=0:0.001:10
y=2*cos(2*pi*20*t);
z=1*cos(2*pi*40*t);
w=3*cos(2*pi*60*t);
x=1+y+z+w;
plot(t,x)

GREATER IN ARRAY

clc;
clear all;
a=input('give the array')
b=a(1);
for i=1:10
if(a(i)>b)
b=a(i);
end
end
disp(b)
SMALLEST IN ARRAY
clc;
clear all;
a=input('give the array')
b=a(1);
for i=1:10
if(a(i)<b)
b=a(i);
end
end
disp(b)

HELIX FUNC

function[x,y,t]=helixfn(r)
t = 0:pi/50:14*pi;
x=r*sin(t);
y=r*cos(t);
plot3(x,y,t,'r*-')

HYPERBOLA

clc;
clear all;
arg1=1:.01:4;
arg2=-4:.01:-1;
line(arg1,sqrt((arg1-1).*(arg1+1)))
line(arg1,-sqrt((arg1-1).*(arg1+1)))
line(arg2,sqrt((arg2-1).*(arg2+1)))
line(arg2,-sqrt((arg2-1).*(arg2+1)))

HYPERBOLA FN
function[]=hyperbolafn(arg1,arg2)
line(arg1,sqrt((arg1-1).*(arg1+1)))
line(arg1,-sqrt((arg1-1).*(arg1+1)))
line(arg2,sqrt((arg2-1).*(arg2+1)))
line(arg2,-sqrt((arg2-1).*(arg2+1)))

PLOT CIRCLE

clc;
clear all;
ang=0:0.0001:2*pi;
r=3;
x=r*cos(ang);
y=r*sin(ang);
plot(x,y,'g*')

PLOT HELIX
clc;
clear all;
t = 0:pi/50:14*pi;
r=1;
x=r*sin(t);
y=r*cos(t);
plot3(x,y,t,'r*-')

PLOT HYPERBOLA

clc;
clear all;
arg1=1:.01:4;
arg2=-4:.01:-1;
line(arg1,sqrt((arg1-1).*(arg1+1)))
line(arg1,-sqrt((arg1-1).*(arg1+1)))
line(arg2,sqrt((arg2-1).*(arg2+1)))
line(arg2,-sqrt((arg2-1).*(arg2+1)))

PRIME

clc;
clear all;
n=input('value of n=');
for i=2:n
c=0;
for j=2:i-1
if(mod(i,j)==0)
c=c+1;

end

end
end
if(c==0)
disp(i)
end

SAREGA
clc
clear all
a=[240,256,288,320,360,400,450,480];
b=0:.001:10
y1=sin(2*pi*240*b);
y2=sin(2*pi*256*b);
y3=sin(2*pi*288*b);
y4=sin(2*pi*320*b);
y5=sin(2*pi*360*b);
y6=sin(2*pi*400*b);
y7=sin(2*pi*450*b);
y8=sin(2*pi*480*b);
y=[y1,y2,y3,y4,y5,y6,y7,y8]
sound(y)

SORT IN ASCEN
clc
clear all
a=input('give the array')
for i=1:10
for j=1:9
if(a(j)>a(j+1))
temp=a(j+1);
a(j+1)=a(j);
a(j)=temp;
end
end
end
disp(a)

SORT IN DESCEN

clc
clear all
a=input('give the array')
for i=1:10
for j=1:9
if(a(j)<a(j+1))
temp=a(j+1);
a(j+1)=a(j);
a(j)=temp;
end
end
end
disp(a)

SPIRAL
clc;

clear all;
ang=-5*pi:0.0001:5*pi;
r=0:.0001:10*pi;
x=r*cos(ang);
y=r*sin(ang);
plot(x,y,'g*')

UNIT IMPULSE
clc;
clear all;
n=5;
x=-5:5;
a=2;
for i=1:2*n+1
y(i)=a^n;
end
stem(x,y);

UNIT IMPULSE WD DELAY


clc;
clear all;
n=5;
x=-5:5;
for i=1:2*n+1
if(x(i)==2)
y(i)=1;
else
y(i)=0;
end
end
stem(x,y);

UNIT RAMP

clc;
clear all;
n=5;
x=-5:5;
for i=1:2*n+1
if(x(i)>=0)
y(i)=x(i);
else
y(i)=0;
end
end
stem(x,y);

UNIT RAMP WD DELAY


clc;
clear all;
n=5;
x=-5:5;
for i=1:2*n+1
if(i>=8)
if(x(i)>=0)
y(i)=x(i);

else

y(i)=0;

end
end
end
stem(x,y);

UNIT STEP 1
clc;
clear all;
n=5;
x=-5:5;
for i=3:2*n+3
if(x(i-2)>=0)
y(i)=1;
else
y(i)=0;
end
end
stem(x,y);

UNIT STEP
clc
clear all
for t=-5:5
if(t>0)
a(t+6)=1;
else
a(t+6)=0;
end
end
stem(t,a)

UNIT STEP WD DELAY


clc;
clear all;
n=5;
x=-5:5;
for i=1:2*n+1
if(i>=8)
if(x(i)>=0)
y(i)=1;
else
y(i)=0;
end
end
end
stem(x,y)

COS ANG
clc;
clear all;
ang=0:.001:2*pi;

t=j*ang;

y=exp(t);
z=exp(-t);
x=(y+z)/2;
plot(ang,x)

CALCULATE MEAN STD DEV


function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = sum(x) / n;
stdev = sqrt(sum((x - mean).^2)/n);

EXPONENTIAL
clc;
clear all;
n=5;
x=-5:5;
for i=1:2*n+1
if(i>=8)
y(i)=exp(x(i));
end
end
stem(x,y);
SINE ANG
clc;
clear all;
ang=0:.001:2*pi;
t=j*ang;
y=exp(t);
z=exp(-t);
x=(y-z)/(2*j);
plot(ang,x)

You might also like