Professional Documents
Culture Documents
'Problem1' 'Problem2' 'Problem3' 'Problem4' 'Problem5' "BFF" "TTYL" 'Problem6'
'Problem1' 'Problem2' 'Problem3' 'Problem4' 'Problem5' "BFF" "TTYL" 'Problem6'
'Problem1' 'Problem2' 'Problem3' 'Problem4' 'Problem5' "BFF" "TTYL" 'Problem6'
%9/29/21
%CS 1972, Program 4
disp('Problem1')
vecout(5)
disp('Problem2')
compare
disp('Problem3')
vector1
disp('Problem4')
airplane
disp('Problem5')
messagesdecode("BFF")
messagesdecode("TTYL")
disp('Problem6')
switch1
Vecout
function [vec]=vecout(n)
vec=n:n+5;
end
compare
function output=exponential(T,t)
output=exp(-T*t);
end
T1=input('Enter the value of the first time constant:');
T2=input('Enter the value of the second time constant:');
t=input('Enter the range of time in a vector form:');
y1=exponential(T1,t);
y2=exponential(T2,t);
plot(t,y1,'r')
hold on
plot(t,y2)
title('Exponential Decay Versus Time')
xlabel('Time')
ylabel('Exponential decay')
vector1
ch=input('Enter any character:','s')
x=linspace(-2*pi,2*pi,50)
y=cos(x)
if ch=='r'
plot(x,y,'-*r')
else
plot(x,y,'-+g')
end
Airplane
aircraft_speed=input('Please enter the speed of the plane in mph:');
sound_speed=input('Please enter the speed of sound at plane''s altitude in
mph:');
ratio=aircraft_speed/sound_speed;
if ratio<1
fprintf('\nFlow is subsonic.\n');
elseif ratio==1
fprintf('\nFlow is transonic.\n');
elseif ratio>1
messagedecode
function out=messagesdecode(myString)
switch myString
case "BFF"
out="best friends forever";
case "BTW"
out="by the way";
case "IDK"
out="I dont't know";
case "IMHO"
out="in my humble opinion";
case "LOL"
out="laughing out loud";
case "TMI"
out="too much information"
otherwise
out="Unknown message";
end
end
Switch1
num=input('Enter the number: ');
switch num
case{0,1,2}
f2(num)
case{-2,-1}
f3(num)
case{3,4}
f4(num)
otherwise
f1(num)
end
function y=f1(x)
y=x^2;
end
function y=f2(x)
y=x^3+1;
end
function y=f3(x)
y=exp(x);
end
function y=f4(x)
y=x+10;
end
>> Program4
Problem1
ans =
5 6 7 8 9 10
Problem2
Problem3
ch =
'f'
x=
Columns 1 through 6
Columns 7 through 12
Columns 13 through 18
Columns 19 through 24
Columns 25 through 30
Columns 31 through 36
Columns 37 through 42
2.9493 3.2057 3.4622 3.7186 3.9751 4.2315
Columns 43 through 48
Columns 49 through 50
6.0267 6.2832
y=
Columns 1 through 6
Columns 7 through 12
Columns 13 through 18
Columns 19 through 24
Columns 31 through 36
Columns 37 through 42
Columns 43 through 48
Columns 49 through 50
0.9673 1.0000
Problem4
Flow is subsonic.
Problem5
ans =
"best friends forever"
ans =
"Unknown message"
Problem6
ans =
14