Question

In: Advanced Math

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

Solutions

Expert Solution

Assumption:

The input file format is not provided. So I used a .txt file with integers in each line.

Assuming inputs to be in celsius I used direct input file for C_to_R function and C_to_F function and for the input of F_to_K function I used the output of C_to_F function.(Check below-Marked in RED)

Program:

function kel=F_to_K(fahr_A) %initiate function
kel=zeros(length(fahr_A),1); % create a output variable to store converted values
for i=1:1:length(fahr_A) % loop to run over all the values
kel(i)= (fahr_A(i)+459.67) * (5/9); % fahr to kelvin conversion
output_file=fopen('F_to_K2.txt','w'); % create a text file to write the output
fprintf(output_file, '%f\n',kel); % store the converted kelvin values in to the files
fclose(output_file); %close the opened files
end

function rankine=C_to_R(Cel_A)
rankine=zeros(length(Cel_A),1);
for i=1:1:length(Cel_A)
rankine(i)= (Cel_A(i)+273.15)*(9/5);
output_file=fopen('C_to_R2.txt','w');
fprintf(output_file, '%f\n',rankine);
fclose(output_file);
end

function fahr=C_to_F(Cel_A)
fahr=zeros(length(Cel_A),1);
for i=1:1:length(Cel_A)
fahr(i)= (Cel_A(i)*1.8) + 32;
output_file=fopen('C_to_F2.txt','w');
fprintf(output_file, '%f\n',fahr);
fclose(output_file);
end

Main function:

clc;
close all;
file_name=fopen('Tempr2.txt', 'r'); %Open the input file
A=fscanf(file_name,'%f'); % read the values in the files to matrix A

fahr=C_to_F(A); % function to convert Celsius to Fahrenheit
%creating table to display conversion
VarNames = {'Celsius','Fahrenheit'}; % Header column for table
T1 = table(A(1:20,:),fahr(1:20,:), 'VariableNames',VarNames) % Values to fill for corresponding column


rankine=C_to_R(A); % function to convert Celsius to Rankine

%creating table to display conversion
VarNames = {'Celsius','Rankine'};
T2 = table(A(1:20,:),rankine(1:20,:), 'VariableNames',VarNames)

kel=F_to_K(fahr); % function to convert Fahrenheit to kelvin
%creating table to display conversion
VarNames = {'Fahrenheit', 'kelvin'};
T3 = table(fahr(1:20,:),kel(1:20,:), 'VariableNames',VarNames)


%%creating table to display properties of output.
VarNames = {'Measurements', 'InputTempurature','OutputofF_to_K', 'OutputofC_to_R', 'OutputofC_to_F'};
measurements=["Mean"; "Median" ; "Variance"; "Standard Deviation"];
input_temp=[mean(A) ; median(A); var(A); std(A)]; %Properties of input data
op_f_k=[mean(kel) ; median(kel); var(kel); std(kel)]; %Properties of output f_to_k
op_c_r=[mean(rankine) ; median(rankine); var(rankine); std(rankine)]; %Properties of output of c_to_r
op_c_f=[mean(fahr) ; median(fahr); var(A); std(fahr)]; %Properties of output of c_to_f
T4 = table(measurements,input_temp, op_f_k, op_c_r, op_c_f, 'VariableNames',VarNames)

Outputs:


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. 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’...
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...
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 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.
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).
QUESTION You are required to obtain a copy of a financial report for STRATEGIC ENERGY RESOURCES...
QUESTION You are required to obtain a copy of a financial report for STRATEGIC ENERGY RESOURCES LIMITED for the year ended 30 June 2019. The best way to locate their financial report is to go to their website and download a copy. This will normally be found under “Investor Information”, “Shareholder Information” or similar tabs on a company’s website. REQUIRED 1)  Identify and explain three key or significant audit matters that were raised in the audit report that may lead to...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT