Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to answer this MATLAB question! 11. Write a matlab function that converts

ID: 3789684 • Letter: I

Question

I need to answer this MATLAB question!

11. Write a matlab function that converts a temperature (in degrees Fahrenheit) to the equivalent temperature in degrees Celcius. OC (oF-32) *5/9. Note: you have to use the function keyword. See http://www.mathworks.com/help/matlab/reflfunction.html on examples of Matlab functions. 10 points) a. Paste the code for your function definition here (5 points) b. Save the function definition in a file with a sensible name. Now create a script (saved under a different name) that uses your function. Suppose we have the temperate vector temp C76.1 72.5 72.4]. Write code (in a script that is separate from your function code) with a for-loop that calls your conversion function to display the following: 76.1 degrees Fahrenheit converts to 24.5 degrees Celcius (5 points) 72.5 degrees Fahrenheit converts to 22.5 degrees Celcius r 72.4 degrees Fahrenheit converts to 22.4 degrees Celcius

Explanation / Answer

The Matlab function Fahrenheit2Celcius.m (save the function as Fahrenheit2Celcius.m)

function C = Fahrenheit2Celcius(F)
% Function to convert degree Fahrenheit to degree Celcius
   C = (F-32)*5/9;
end

Part b) script to test the function Fahrenheit2Celcius.m

temp = [76.1 72.5 72.4];% Temperature vector in Fahrenheit
for k=1:3
   C= Fahrenheit2Celcius(temp(k)); % Calling the function Fahrenheit2Celcius
   % Results
   fprintf('%2.1f degree Fahrenheit converts to %2.1f degree Celcius ',temp(k),C);
end

Output of part b)

76.1 degree Fahrenheit converts to 24.5 degree Celcius
72.5 degree Fahrenheit converts to 22.5 degree Celcius
72.4 degree Fahrenheit converts to 22.4 degree Celcius

Part c)

temp = [70 75 72 68 70 71 73];% Temperature vector in Fahrenheit
day = {'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'};
for k=1:7
   fprintf('The temperature on %s is %d degrees ',day{k},temp(k));
end

Output

The temperature on Monday is 70 degrees
The temperature on Tuesday is 75 degrees
The temperature on Wednesday is 72 degrees
The temperature on Thursday is 68 degrees
The temperature on Friday is 70 degrees
The temperature on Saturday is 71 degrees
The temperature on Sunday is 73 degrees

part d)

while-end loop will continue repetitions until the logic statement is false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote