You are on page 1of 5

Assignment Programming

1. x=[45,23,17,34,85,29,13,89,100,101,79,80,99,1,5,6,7,3]
count=sum(x)
for k=1:length(x)
end
>> Untitled
x=
Columns 1 through 7
45

23

17

34

85

29

13

Columns 8 through 14
89 100 101 79 80 99
Columns 15 through 18
5

count =
816

2. Temperature=menu('You can decide the unit of temperature to


display','Celcius','Farenheit');
switch Temperature
case 1
x=input('Enter the scalar value for the outside air temperature
in Celcius:');
x=(x*9/5)+32
if x>=80 ;
disp('You need to wear shorts')
else if 60>x<80;
disp('It indeed a beutiful day')
else
disp('You are advised to wear jacket or something')
end
end
case 2
y=input('Enter the scalar value for the outside air temperature
is Farenheit:');
if y>=80;
disp('You need to wear shorts')
else if 60>y<80;
disp('It indeed a beutiful day')
else
disp('You are advised to wear jacket or something')
end
end
End
>> Untitled2
Enter the scalar value for the outside air temperature in Celcius:27
x=
80.6000
You need to wear shorts

3.a)x=input('Enter the value from 0 to 100:');


if x<=100&&x>0,
if x<=100&&x>=90,
disp('A')
end
if x<90&&x>=80;
disp('B')
end
if x<80&&x>=70;
disp('C')
end
if x<70&&x>60;
disp('D')
end
if x<60&&x>=0,
disp('F')
end
else
disp('input error')
End
>> Untitled3
Enter the value from 0 to 100:25
F

3.b)x=input('Enter the value from o to 100:');


if x<=100&&x>=90;
disp('A')
elseif x<90&&x>=80;
disp('B')
elseif x<80&&x>=70;
disp('C')
elseif x<70&&x>=60;
disp('D')
elseif x<60&&x>=0;
disp('F')
else
disp('Input error')
end
>> Untitled4
Enter the value from o to 100:87
B

4.x=[0:0.01:35];
y=0.4*sqrt(1.8.*x);
plot(x,y)
xlabel('x')
ylabel('y')
title('equation y')
axis([0 35 0 3.5])

5.x=[0:0.01:2];
y=sinh(x);
z=0.5.*exp(x);
plot(x,y,x,z),xlabel('x'),ylabel('y'),gtext('sinh(x)'),gtext('0.5*exp(x)')

You might also like