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

INDIVIDUAL COURSEWORK

MM1CPM-Computer Programming with MATLAB


Course Work 1
Ngiam Yen Kui 024071 Course-H300
Question 1.
%part1
x=linspace(2*pi,2*pi,50)
y=sin(x)
subplot(2,3,1)
plot(y)
title('y=sin(x)')
xlabel('radian')
%part2
x=linspace(2*pi,2*pi,50)
y=1./x
subplot(2,3,2)
plot(y)
title('y=1/x')
xlabel('radian')
%part3
x=linspace(2*pi,2*pi,50)
y=exp(x.^(2))
subplot(2,3,3)
plot(y)
title('y=exp(x.^(2))')
xlabel('radian')
%part4
x=linspace(2*pi,2*pi,50)
y=(((exp(x))(exp(x)))/2)
subplot(2,3,4)
plot(y)
title('y=(((exp(x))(exp(x)))/2)')
xlabel('radian')
%part5
x=linspace(2*pi,2*pi,50)
y=log(x+sqrt((x.^2)+1))
subplot(2,3,5)
plot(y)
title('y=log(x+sqrt((x.^2)+1))')
xlabel('radian')

1) y=sin(x)

2) y=1/x

10

0.5

-0.5

-5

3) y=exp(-x.(2))

1
0.8
0.6
0.4

-1

20

40

radian

60

4) y=(((exp(x))-(exp(-x)))/2)

-10
-10

300

200

100

-100

-1

-200

-2

-300

20

40

radian

60

0.2

-3

radian

10

5) y=log(x+sqrt((x.2)+1))

20

40

radian

60

Question 2.
a=270
b=140
c=1200
a=input('Whatisthevalueofa?/n')
b=input('Whatisthevalueofb?/n')
c=input('Whatisthevalueofc?/n')
z1=((bsqrt(b^24*a*c))/(2*a))
z2=((bsqrt(b^24*a*c))/(2*a))
disp('')
disp('z1=');disp(z1);
disp('z2=');disp(z2);
disp('')
fprintf('Realpartofz1is%f',real(z1));
fprintf('Imaginarypartofz1is%f\n',imag(z1));
fprintf('Absolutevalueofz1is%f\n'abs(z1));
fprintf('Arguementofz1is%f\n'angle(z1);
fprintf('Realpartofz2is%f',real(z2));
fprintf('Imaginarypartofz2is%f\n',imag(z2));
fprintf('Absolutevalueofz2is%f\n'abs(z2));
fprintf('Arguementofz2is%f\n'angle(z2);

Question 3.
Eo=8.85418782*(10^12)
Mo=4*pi*10^7
Er=[1:12]
c=sqrt(1./(Er*Eo*Mo))
plot(Er,c)
title('EragainstSpeedoflight')
xlabel('m*s^1')
ylabel('arbitaryunit')

20

40

radian

60

10

Er against Speed of light

2.5

arbitary unit

1.5

0.5

10

12

m*s- 1

Question 4.
%1clear
commandtodeletethevariablesintheworkspace
%2figure

%3xlabel
commandtolabelthexaxis
%4plot
commandtosketchgraphofthedataoffirstvariableagainstthedataof
secondvariable
%5surf

Question 5.
A=randi(8,8)%1
B=zeros(8,8)%2
D=ones(8)%3
D(logical(eye(size(D))))=0
E=A;E(:,4)=B(:,4)%4
F=transpose(A)%5
Z=round(rand(5)*2010)%6
T=diag(ones(5,1))%7
G=Z*T%8
H=Z.^(T*2)%9
R=[Z;T]%10

Question 6.

You might also like