Question

In: Electrical Engineering

Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...

Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution.

Develop three functions for temperature-conversion.

  • Create a function called F_to_K that converts and return temperatures in Fahrenheit to Kelvin and store results in ‘F_to_K2.txt’.
  • Create a function called C_to_R that converts and return temperatures in Celsius to Rankine and store results in ‘C_to_R2.txt’.
  • Create a function called C_to_F that converts and return temperatures in Celsius to Fahrenheit and store results in ‘C_to_F2.txt’.

Use the following equations to achieve these conversions.

1 degree Fahrenheit =255.928 Kelvin

1 degree Celsius =493.47 Rankine

1 degree Celsius =33.8 degrees Fahrenheit

  • Write an appropriate MATLAB code to collectively call and test these functions.
    • It should import data from ‘Tempr2.txt’ and convey it to each of the above mentioned user defined functions. ‘Tempr2.txt’ is available on BlackBoard under the folder Final_Exam.
    • It should display on the command window one conversion table for each case while displaying first 20 inputs and converted values.
    • It should also display a table on the command window, which presents the mean, median, variance and standard deviation values according to the following Table.

Measurements

       Input

Temperature

Output of

   F_to_K

Output of

   C_to_R

Output of

   C_to_F

Mean

Median

Variance

Standard

Deviation

Tempr2

70.000000
54.000000
-58.000000
-4.000000
-32.000000
17.000000
110.000000
-39.000000
102.000000
-18.000000
-28.000000
35.000000
40.000000
19.000000
-68.000000
-30.000000
-38.000000
-21.000000
-34.000000
26.000000
56.000000
-8.000000
33.000000
43.000000
12.000000
-9.000000
-22.000000
-53.000000
-9.000000
13.000000
-4.000000
16.000000
7.000000
39.000000
-27.000000
-1.000000
17.000000
-14.000000
19.000000
-84.000000
28.000000
28.000000
5.000000
-13.000000
-17.000000
-80.000000
60.000000
37.000000
-49.000000
-69.000000
-14.000000
39.000000
47.000000
32.000000
43.000000
93.000000
-80.000000
28.000000
2.000000
-32.000000
41.000000
5.000000
65.000000
-47.000000
-37.000000
27.000000
-39.000000
11.000000
-15.000000
60.000000
27.000000
-15.000000
-27.000000
-15.000000
125.000000
3.000000
-5.000000
-5.000000
81.000000
-82.000000
61.000000
-31.000000
-9.000000
39.000000
-42.000000
26.000000
1.000000
-65.000000
15.000000
34.000000
37.000000
-23.000000
4.000000
36.000000
32.000000
-14.000000
-59.000000
19.000000
21.000000
80.000000
-73.000000
-13.000000
27.000000
-0.000000
106.000000
-13.000000
-113.000000
41.000000
-65.000000
71.000000
25.000000
-12.000000
-44.000000
98.000000
20.000000
-19.000000
-30.000000
-4.000000
68.000000
101.000000
6.000000
26.000000
21.000000
-77.000000
12.000000
-20.000000
-16.000000
-3.000000
-140.000000
-32.000000
43.000000
11.000000
-21.000000
-12.000000
-49.000000
-30.000000
-24.000000
-4.000000
34.000000
4.000000
1.000000
-37.000000
54.000000
17.000000
33.000000
16.000000
45.000000
81.000000
-17.000000
32.000000
39.000000
5.000000
101.000000
-44.000000
-19.000000
9.000000
6.000000
-6.000000
-19.000000
46.000000
2.000000
-35.000000
91.000000
51.000000
79.000000
4.000000
101.000000
51.000000
-85.000000
-58.000000
34.000000
-1.000000
-2.000000
59.000000
90.000000
25.000000
11.000000
118.000000
4.000000
-18.000000
-25.000000
-32.000000
9.000000
-38.000000
-88.000000
-59.000000
27.000000
60.000000
65.000000
121.000000
-49.000000
73.000000
9.000000
-18.000000
-16.000000
49.000000
37.000000
-85.000000
56.000000
46.000000
-7.000000
-44.000000
-33.000000
-57.000000
2.000000
-14.000000
-11.000000
16.000000
-10.000000
-80.000000
-25.000000
-21.000000
-81.000000
49.000000
-103.000000
26.000000
-10.000000
-13.000000
37.000000
-10.000000
-6.000000
-39.000000
61.000000
55.000000
39.000000
32.000000
41.000000
40.000000
25.000000
37.000000
-30.000000
6.000000
33.000000
-31.000000
5.000000
-4.000000
67.000000
29.000000
60.000000
36.000000
55.000000
0.000000
11.000000
-26.000000
24.000000
159.000000
10.000000
3.000000
48.000000
-73.000000
61.000000
-37.000000
33.000000
19.000000
2.000000
-31.000000
26.000000
61.000000
39.000000
75.000000
-64.000000
6.000000
-63.000000
11.000000
32.000000
-33.000000
69.000000
-19.000000
36.000000
-12.000000
-33.000000
-32.000000
-68.000000
81.000000
-117.000000
-60.000000
-94.000000
-62.000000
-135.000000
35.000000
7.000000
-47.000000
-60.000000
-61.000000
-9.000000
-96.000000
25.000000
1.000000
-12.000000
38.000000
22.000000
-12.000000
7.000000
-2.000000
-26.000000
61.000000
65.000000
9.000000
-46.000000
-54.000000
18.000000
-8.000000
-36.000000
12.000000
-54.000000
22.000000
-75.000000
-118.000000
-5.000000
-44.000000
82.000000
74.000000
-26.000000
-43.000000
-6.000000
-11.000000
74.000000
-12.000000
65.000000
67.000000
131.000000
-14.000000
-19.000000
89.000000
-32.000000
-86.000000
9.000000
30.000000
-13.000000
-13.000000
-63.000000
91.000000
15.000000
-22.000000
25.000000
47.000000
-47.000000
16.000000
-19.000000
88.000000
13.000000
-51.000000
-1.000000
27.000000
110.000000
7.000000
34.000000
65.000000
30.000000
-38.000000
-3.000000
-28.000000
40.000000
82.000000
4.000000
58.000000
-30.000000
13.000000
-4.000000
87.000000
20.000000
43.000000
-12.000000
-27.000000
25.000000
-36.000000
-63.000000
-10.000000
85.000000
-15.000000
16.000000
-25.000000
-98.000000
5.000000
90.000000
-12.000000
-53.000000
-45.000000
23.000000
-16.000000
54.000000
-9.000000
-99.000000
-17.000000
41.000000
56.000000
69.000000
55.000000
59.000000
100.000000
82.000000
14.000000
-19.000000
-9.000000
40.000000
65.000000
-7.000000
81.000000
-31.000000
-18.000000
-14.000000
-28.000000
48.000000
-4.000000
98.000000
5.000000
98.000000
-116.000000
23.000000
19.000000
102.000000
18.000000
94.000000
100.000000
-26.000000
-55.000000
48.000000
-36.000000
-3.000000
-24.000000
10.000000
35.000000
41.000000
12.000000
-42.000000
-37.000000
20.000000
-104.000000
-54.000000
-73.000000
-11.000000
29.000000
123.000000
5.000000
-48.000000
-18.000000
28.000000
56.000000
-18.000000
5.000000
64.000000
16.000000
9.000000
-12.000000
-14.000000
58.000000
-22.000000
3.000000
-47.000000
35.000000
17.000000
27.000000
4.000000
-32.000000
1.000000
-59.000000
-12.000000
120.000000
89.000000
48.000000
27.000000
46.000000
24.000000
52.000000
65.000000
-46.000000
-5.000000
4.000000
-23.000000
-45.000000
69.000000
38.000000
-41.000000
-48.000000
26.000000
-29.000000
-55.000000
-7.000000
-37.000000
47.000000
120.000000
-80.000000
47.000000
26.000000
-37.000000
53.000000
-39.000000
-89.000000
-51.000000
34.000000
26.000000
55.000000
30.000000
68.000000
-95.000000
-10.000000
-13.000000
2.000000
58.000000
-29.000000
18.000000
-91.000000
-41.000000
52.000000
-82.000000
76.000000
-19.000000
31.000000
-54.000000
43.000000
5.000000
68.000000
-22.000000
-32.000000
-33.000000
104.000000
-11.000000
-75.000000
52.000000
6.000000
-13.000000
31.000000
49.000000
-27.000000
11.000000
-11.000000
-24.000000
29.000000
41.000000
-64.000000
61.000000
12.000000
-7.000000
-74.000000
-8.000000
2.000000
10.000000
-17.000000
51.000000
83.000000
67.000000
-7.000000
22.000000
25.000000
-26.000000
4.000000
-24.000000
8.000000
86.000000
-4.000000
-32.000000
74.000000
49.000000
-21.000000
-32.000000
76.000000
7.000000
14.000000
22.000000
-26.000000
59.000000
123.000000
-119.000000
15.000000
52.000000
-35.000000
9.000000
14.000000
-25.000000
40.000000
66.000000
16.000000
23.000000
-22.000000
61.000000
0.000000
27.000000
64.000000
-10.000000
-5.000000
10.000000
-6.000000
-58.000000
29.000000
-67.000000
-10.000000
-65.000000
70.000000
9.000000
29.000000
-8.000000
84.000000
-15.000000
63.000000
63.000000
-21.000000
26.000000
11.000000
111.000000
-45.000000
-74.000000
21.000000
-43.000000
-24.000000
22.000000
-60.000000
59.000000
26.000000
76.000000
-11.000000
51.000000
-51.000000
17.000000
61.000000
-27.000000
9.000000
87.000000
-34.000000
-51.000000
52.000000
4.000000
-50.000000
-40.000000
22.000000
17.000000
-13.000000
16.000000
33.000000
-32.000000
-11.000000
-31.000000
72.000000
-59.000000
86.000000
-23.000000
5.000000
53.000000
42.000000
-12.000000
49.000000
-54.000000
74.000000
63.000000
6.000000
25.000000
54.000000
-11.000000
32.000000
39.000000
24.000000
-66.000000
-12.000000
-94.000000
-14.000000
-34.000000
0.000000
24.000000
47.000000
-2.000000
7.000000
56.000000
70.000000
16.000000
48.000000
-31.000000
84.000000
-28.000000
-33.000000
32.000000
2.000000
-74.000000
59.000000
40.000000
87.000000
20.000000
40.000000
-53.000000
98.000000
124.000000
-14.000000
-30.000000
55.000000
-52.000000
13.000000
-2.000000
46.000000
-93.000000
11.000000
18.000000
-84.000000
-3.000000
36.000000
-59.000000
-10.000000
15.000000
-21.000000
84.000000
43.000000
-24.000000
22.000000
61.000000
17.000000
33.000000
37.000000
42.000000
-61.000000
-29.000000
-13.000000
-75.000000
-65.000000
23.000000
23.000000
51.000000
23.000000
-33.000000
4.000000
-31.000000
48.000000
-71.000000
48.000000
30.000000
44.000000
-24.000000
15.000000
3.000000
-71.000000
29.000000
27.000000
-32.000000
67.000000
-83.000000
-16.000000
-15.000000
-31.000000
-28.000000
29.000000
-39.000000
8.000000
-16.000000
-1.000000
102.000000
-22.000000
49.000000
7.000000
7.000000
-90.000000
56.000000
13.000000
-17.000000
7.000000
-0.000000
97.000000
-50.000000
-23.000000
18.000000
98.000000
18.000000
61.000000
43.000000
41.000000
69.000000
120.000000
12.000000
-10.000000
14.000000
-10.000000
-111.000000
-1.000000
13.000000
-13.000000
-6.000000
67.000000
9.000000
4.000000
-28.000000
-23.000000
-0.000000
11.000000
24.000000
87.000000
73.000000
-55.000000
93.000000
-44.000000
134.000000
15.000000
-17.000000
-96.000000
-15.000000
82.000000
-16.000000
-18.000000
-61.000000
-54.000000
-24.000000
23.000000
-98.000000
38.000000
-19.000000
45.000000
5.000000
-17.000000
30.000000
30.000000
106.000000
-60.000000
-30.000000
-56.000000
-24.000000
-20.000000
-17.000000
-18.000000
-21.000000
-7.000000
26.000000
61.000000
-13.000000
96.000000
49.000000
66.000000
-44.000000
-86.000000
21.000000
22.000000
-80.000000
-69.000000
23.000000
57.000000
73.000000
-41.000000
35.000000
36.000000
3.000000
-48.000000
-50.000000
42.000000
-79.000000
-10.000000
12.000000
60.000000
-13.000000
-65.000000
22.000000
-31.000000
94.000000
-38.000000
14.000000
107.000000
58.000000
4.000000
29.000000
125.000000
75.000000
-61.000000
14.000000
58.000000
-72.000000
19.000000
2.000000
19.000000
-35.000000
-86.000000
-49.000000
99.000000
-1.000000
-43.000000
78.000000
51.000000
-38.000000
59.000000
61.000000
-34.000000
32.000000
-14.000000
68.000000
-58.000000
-15.000000
46.000000
1.000000
34.000000
92.000000
-16.000000
-50.000000
83.000000
-17.000000
21.000000
-24.000000
-73.000000
-42.000000
71.000000
-16.000000
-3.000000
20.000000
64.000000
13.000000
-8.000000
-38.000000
34.000000
-99.000000
-54.000000
42.000000
27.000000
-59.000000
32.000000
28.000000
-54.000000
1.000000
85.000000
-20.000000
-62.000000
13.000000
-23.000000
-13.000000
26.000000
2.000000
-14.000000
-47.000000
-36.000000
-46.000000
-25.000000
93.000000
12.000000
-22.000000
-1.000000
17.000000
19.000000
21.000000
60.000000
-12.000000
23.000000
-26.000000
-88.000000
-24.000000
76.000000
-13.000000
56.000000
35.000000
-25.000000
101.000000
49.000000
50.000000
-40.000000
-27.000000
37.000000
65.000000
4.000000
91.000000
-1.000000
41.000000
5.000000
60.000000
-11.000000
3.000000
-70.000000
20.000000
9.000000
31.000000
22.000000
-28.000000
38.000000
136.000000
-27.000000
52.000000
-24.000000
-40.000000
-51.000000
34.000000
7.000000
49.000000
-5.000000
-54.000000
-5.000000
1.000000
36.000000
-56.000000
-87.000000
28.000000
-34.000000
-20.000000
33.000000
6.000000
13.000000
64.000000
58.000000
5.000000
-22.000000
-55.000000
21.000000
121.000000
57.000000
16.000000
-50.000000
-56.000000
-22.000000
-182.000000
26.000000
67.000000
11.000000
-11.000000
73.000000

Solutions

Expert Solution

%matlab

T=readtable('Tempr2.txt');
F_to_K=@(t) (t-32)*(5/9)+273.15;
C_to_R=@(t) t*(9/5) + 491.67;
C_to_F=@(t) t*(9/5) + 32;
t=T.Tempr2;
t_F_K=F_to_K(t);
t_C_R=C_to_R(t);
t_C_F=C_to_F(t);
T_F_K=table(t(1:20),t_F_K(1:20),'VariableNames',{'temperature_Fahrenheit','temperature_Kelvin'})
T_C_R=table(t(1:20),t_C_R(1:20),'VariableNames',{'temperature_Celsius','temperature_Rankine'})
T_C_F=table(t(1:20),t_C_F(1:20),'VariableNames',{'temperature_Celsius','temperature_Fahreheit'})
t_mean=mean(t);
t_median=median(t);
t_variance=var(t);
t_std=std(t);
t_F_K_mean=mean(t_F_K);
t_F_K_median=median(t_F_K);
t_F_K_variance=var(t_F_K);
t_F_K_std=std(t_F_K);
t_C_R_mean=mean(t_C_R);
t_C_R_median=median(t_C_R);
t_C_R_variance=var(t_C_R);
t_C_R_std=std(t_C_R);
t_C_F_mean=mean(t_C_F);
t_C_F_median=median(t_C_F);
t_C_F_variance=var(t_C_F);
t_C_F_std=std(t_C_F);
Measurements={'mean';'median';'variance';'std'};
input_temperature=[t_mean;t_median;t_variance;t_std];
output_F_K=[t_F_K_mean;t_F_K_median;t_F_K_variance;t_F_K_std];
output_C_R=[t_C_R_mean;t_C_R_median;t_C_R_variance;t_C_R_std];
output_C_F=[t_C_F_mean;t_C_F_median;t_C_F_variance;t_C_F_std];
Statistics=table(Measurements,input_temperature,output_F_K,output_C_R,output_C_F)

---------------------------------------

%result

>> m3

T_F_K =

temperature_Fahrenheit temperature_Kelvin
______________________ __________________

70 294.26
54 285.37
-58 223.15
-4 253.15
-32 237.59
17 264.82
110 316.48
-39 233.71
102 312.04
-18 245.37
-28 239.82
35 274.82
40 277.59
19 265.93
-68 217.59
-30 238.71
-38 234.26
-21 243.71
-34 236.48
26 269.82


T_C_R =

temperature_Celsius temperature_Rankine
___________________ ___________________

70 617.67   
54 588.87   
-58 387.27   
-4 484.47   
-32 434.07   
17 522.27   
110 689.67   
-39 421.47   
102 675.27   
-18 459.27   
-28 441.27   
35 554.67   
40 563.67   
19 525.87   
-68 369.27   
-30 437.67   
-38 423.27   
-21 453.87   
-34 430.47   
26 538.47   


T_C_F =

temperature_Celsius temperature_Fahreheit
___________________ _____________________

70 158
54 129.2
-58 -72.4
-4 24.8
-32 -25.6
17 62.6
110 230
-39 -38.2
102 215.6
-18 -0.4
-28 -18.4
35 95
40 104
19 66.2
-68 -90.4
-30 -22
-38 -36.4
-21 -5.8
-34 -29.2
26 78.8


Statistics =

Measurements input_temperature output_F_K output_C_R output_C_F
____________ _________________ __________ __________ __________

'mean' 6.537 259 503.44 43.767
'median' 5 258.15 500.67 41
'variance' 2384.2 735.85 7724.6 7724.6
'std' 48.828 27.127 87.89 87.89

>>

--------------------


Related Solutions

Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Develop three functions for temperature-conversion. Create a function called F_to_K that converts and return temperatures in Fahrenheit to Kelvin and store results in ‘F_to_K2.txt’. Create a function called C_to_R that converts and return temperatures in Celsius to Rankine and store results in ‘C_to_R2.txt’. Create a function called C_to_F that...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Write a user defined function ‘My_FunctionGen’. It accepts, the time vector ‘t’ with 8000 uniformly spaced values within the range of 0 to 8, Frequecy scalars ‘f1<100H’ and ‘f2<80Hz’ and Amplitude scalars ‘A1’, ‘A2’ and ‘A3’ as input arguments. It delivers x1, x2 and x3 and x4 as outputs...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Generate the following vectors and also implement the Table-1 operations-map by employing the switch statement and an appropriate loop. Generate a vector ‘DEC1’ as follow. DEC1 = 5     1     3     0     2    5     0     2 Concatenate vector ‘DEC1’ eight times in order to obtain a bigger row vector ‘DEC’...
this is my matlab code for class, my professor commented "why is the eps an input...
this is my matlab code for class, my professor commented "why is the eps an input when it is set inside the function and not specified as a variable? how do i fix? function[] = () %Declare Global Variables global KS; global KC; KC = 0; KS = 0; End = 0; while (End == 0) choice = questdlg('Choose a function', ... 'Fuction Menu', ... 'A','B','B'); switch choice; case 'A' Program = 'Start'; while strcmp(Program,'Start'); Choice = menu('Enter the Trigonometric...
Use Matlab to write the following 1. Write code to determine whether a year is a...
Use Matlab to write the following 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100, but not by 400, are not leap years. Years divisible by 4, but not by 100, are leap years. All other years are not leap years. For example, the years 1800,...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
Write a matlab code to do following steps; i) Record your voice by sampling frequency 22...
Write a matlab code to do following steps; i) Record your voice by sampling frequency 22 kHz ii) Down sample the voice by 2 listen to your voice iii) Down sample the voice by 3 listen to your voice Please explain the code clearly. Thank you.
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
Write an Matlab Program for Wankel Engine Gemontry. State your and assumptions and post the code
Write an Matlab Program for Wankel Engine Gemontry. State your and assumptions and post the code
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT