'Problem1' 'Problem2' 'Problem3' 'Problem4' 'Problem5' "BFF" "TTYL" 'Problem6'

You might also like

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

%Jeriah Jordan

%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

Enter the value of the first time constant:5

Enter the value of the second time constant:10

Enter the range of time in a vector form:[0:0.1:5]

Problem3

Enter any character:f

ch =

'f'
x=

Columns 1 through 6

-6.2832 -6.0267 -5.7703 -5.5138 -5.2574 -5.0009

Columns 7 through 12

-4.7444 -4.4880 -4.2315 -3.9751 -3.7186 -3.4622

Columns 13 through 18

-3.2057 -2.9493 -2.6928 -2.4363 -2.1799 -1.9234

Columns 19 through 24

-1.6670 -1.4105 -1.1541 -0.8976 -0.6411 -0.3847

Columns 25 through 30

-0.1282 0.1282 0.3847 0.6411 0.8976 1.1541

Columns 31 through 36

1.4105 1.6670 1.9234 2.1799 2.4363 2.6928

Columns 37 through 42
2.9493 3.2057 3.4622 3.7186 3.9751 4.2315

Columns 43 through 48

4.4880 4.7444 5.0009 5.2574 5.5138 5.7703

Columns 49 through 50

6.0267 6.2832

y=

Columns 1 through 6

1.0000 0.9673 0.8713 0.7183 0.5184 0.2845

Columns 7 through 12

0.0321 -0.2225 -0.4625 -0.6723 -0.8381 -0.9491

Columns 13 through 18

-0.9979 -0.9816 -0.9010 -0.7614 -0.5721 -0.3454

Columns 19 through 24

-0.0960 0.1596 0.4048 0.6235 0.8014 0.9269


Columns 25 through 30

0.9918 0.9918 0.9269 0.8014 0.6235 0.4048

Columns 31 through 36

0.1596 -0.0960 -0.3454 -0.5721 -0.7614 -0.9010

Columns 37 through 42

-0.9816 -0.9979 -0.9491 -0.8381 -0.6723 -0.4625

Columns 43 through 48

-0.2225 0.0321 0.2845 0.5184 0.7183 0.8713

Columns 49 through 50

0.9673 1.0000

Problem4

Please enter the speed of the plane in mph:1561

Please enter the speed of sound at plane's altitude in mph:45463

Flow is subsonic.

Problem5

ans =
"best friends forever"

ans =

"Unknown message"

Problem6

Enter the number: 4

ans =

14

You might also like