Professional Documents
Culture Documents
TASK 2:
% Program to understand the use of a function file
% This function computes the sum and the product of 2 matrices
function [sm,pro]=oper(A,B)
sm=A+B
pro=A*B
end
RESULTS:
Figure 2 task 2.
TASK 3:
Script:
x=-2:2 % independent variable ,length of the plot
length (x)
y=x.^2 % Function
length (y)
plot(x,y)
RESULTS:
Figure 3 task 3.
TASK 4.1:
x = linspace(0,2*pi,100) % linspace could be used to create a vector.
x=0:pi/50:2*pi % this is same value as above. Both method are correct
y = (x.^2).*cos(x);
g = x.*cos(x);
f = (2.^x).*sin(x);
plot(x,y,x,g,x,f)
RESULTS:
Figure 4 task 4.1.
TASK 4.2:
x = linspace(0,2*pi,150);
plot(x,cos(x),'r*',x,sin(x),'k')
xlabel('Time Axis')
ylabel('Amplitude')
title('Graph of cos(x) & sin(x)')
legend('cos','sine')
RESULTS:
Figure 5 task 4.2.
TASK 5.1:
x=linspace(0,2*pi,150);
plot(x,double(x),'r*',x,sin(x),'k')
plot(x,cos(x),'r*')
title('Graph of Cos(x)')
RESULTS:
Figure 6 task 5.
TASK 5.2
x=linspace(0,2*pi,150);
plot(x,double(x),'r*',x,sin(x),'k')
plot(x,sin(x),'k')
title('Graph of sin(x)')
RESULTS:
x=linspace(0,2*pi,150);
plot(x,double(x),'r*',x,sin(x),'k')
subplot 211
plot(x,cos(x),'r*')
subplot 212
plot(x,sin(x),'k')
RESULTS:
TASK 6:
n = -3:3
f= n.^2
stem(n,f)
xlabel('Time Axis')
ylabel('Amplitude')
title('Graph of f(n)')
RESULTS:
Figure 9 task 6.
TASK 6.1:
n= -3:0.1:3;
f=n.^2;
stem(n,f)
xlabel('Time Axis')
ylabel('Amplitude')
title('Graph of f(n)')
RESULTS:
Figure 10 task 6.1.
TASK 7:
RESULTS:
Figure 11 task 7.