MATLAB: A Practical Introduction to Programming and Problem Solving
MATLAB: A Practical Introduction to Programming and Problem Solving
5th Edition
ISBN: 9780128154793
Author: Stormy Attaway Ph.D. Boston University
Publisher: Elsevier Science
bartleby

Concept explainers

bartleby

Videos

Question
Book Icon
Chapter 6, Problem 22E
To determine

To write:

• A program to call a function that explains what the program will do.

• A program to call a function to prompt the user for the minimum and maximum temperatures in degrees Fahrenheit, and return both values.

• A program to call a function to write temperature to a file as the temperature in degrees F from the minimum to the maximum in one column and the corresponding temperature in degrees Celsius in another column.

Expert Solution & Answer
Check Mark

Answer to Problem 22E

Solution:

• % MATLAB code to explain about the working of program.

%function file.

function explainprogram

%explain the working of the program by using the function explainprogram.

disp('In this program the maximum and minimum tempertaures are descibed in degrees Fahrenheit.')

disp('the conversion chart of temperature will be created by the program and')

disp('the conversion will be between the Fahrenheit to celsius and save the chart in a file')

disp('called Fartocel.dat')

end

% end of function

• % MATLAB code for asking the user to the minimum and maximum value of temperature in degree and Fahrenheit.

%function file.

function[minimum, maximum] = mintomaxtemp

%Ask the user to the minimum and maximum value of temperature by using the function mintomaxtemp.

minimum = input('the minimum temperature is enterted:');

%define the variable minimum.

maximum = input ('the maximum temperature is entered:');

%define the variable maximum.

[minimum, maximum] = changetemp(minimum, maximum);

end

function [minimum, maximum] = changetemp(minimum, maximum)

%Ask the user to the minimum and maximum value of temperature. in

%degree and Fahrenheit by using the function changetemp.

if maximum<minimum;

temperature = maximum;

maximum = minimum;

minimum = temperature;

end

end

% end of function

• The script file is,

%MATLAB code to write a temperature file in degrees and Fahrenheit in

%different columns and save in a data file.

%function file.

Function [F, C]=charttempertaure(minimum, maximum);

%write a temperature file in degrees and Fahrenheit in different columns by

%using the function charttemperature.

F = [minimum:maximum];

%define the variable F.

C = (F-32)*5/9;

%define the variable C;

tempchart = [F' C'];

save Fartocel.dat tempchart -ascii

end

% end of function

%The script file should be placed in the same folder.

The main script file is,

%MATLAB code to write a temperature file in a chart.

%main script file.

explainprogram

[minimum, maximum] = mintomaxtemp;

charttempertaure(minimum, maximum)

% end of file

Explanation of Solution

• A program to call a function that explains what the program will do.

In the program the minimum and maximum temperature are described in degrees and Fahrenheit. The conversion chart from Fahrenheit to Celsius will be created by the program and save in a data file.

MATLAB Code:

%MATLAB code to write a temperature file in a chart.

%main script file.

clc

clear all

close all

explainprogram

[minimum, maximum] = mintomaxtemp;

[F, C]=charttempertaure(minimum, maximum);

% end of file

%The script file should be placed in the same folder.

% MATLAB code to explain about the working of program.

%function file.

function explainprogram

%explain the working of the program by using the function explainprogram.

disp('In this program the maximum and minimum tempertaures are descibed in degrees Fahrenheit.')

disp('the conversion chart of temperature will be created by the program and')

disp('the conversion will be between the Fahrenheit to celsius and save the chart in a file')

disp('called Fartocel.dat')

end

% end of function

Save the MATLAB script with name, explainprogram.m in the current folder. Execute the script by typing the script name at the command window to generate output.

Result:

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 6, Problem 22E , additional homework tip  1

Therefore, the result is stated above.

• A program to call a function to prompt the user for the minimum and maximum temperatures in degrees Fahrenheit, and return both values.

Consider the minimum value of temperature is 190 and the maximum value of the temperature is 200.

MATLAB Code:

% MATLAB code for asking the user to the minimum and maximum value of temperature in degree and Fahrenheit.

%function file.

function[minimum, maximum] = mintomaxtemp

%Ask the user to the minimum and maximum value of temperature by using the function mintomaxtemp.

minimum = input('the minimum temperature is enterted:');

%define the variable minimum.

maximum = input ('the maximum temperature is entered:');

%define the variable maximum.

[minimum, maximum] = changetemp(minimum, maximum);

end

function [minimum, maximum] = changetemp(minimum, maximum)

%Ask the user to the minimum and maximum value of temperature. in

%degree and Fahrenheit by using the function changetemp.

if maximum<minimum;

temperature = maximum;

maximum = minimum;

minimum = temperature;

end

end

% end of function

Save the MATLAB script with name, mintomaxtemp.m in the current folder. Execute the script by typing the script name at the command window to generate o

Result:

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 6, Problem 22E , additional homework tip  2

Therefore, the result is stated above.

• A program to call a function to write temperature to a file as the temperature in degrees F from the minimum to the maximum in one column and the corresponding temperature in degrees Celsius in another column.

Consider the minimum value of temperature is 190 and the maximum value of the temperature is 200.

The conversion formula is given as,

C=5(F32)9

Substitute 190 for F in the above formula.

C=5(19032)9C=87.7778

Substitute 200 for F in the above formula.

C=5(20032)9C=93.333

MATLAB Code:

%MATLAB code to write a temperature file in degrees and Fahrenheit in

%different columns and save in a data file.

%function file.

function charttempertaure(minimum, maximum)

%write a temperature file in degrees and Fahrenheit in different columns by

%using the function charttemperature.

F = [minimum:maximum];

%define the variable F.

C = (F-32)*5/9;

%define the variable C;

tempchart = [F' C'];

save Fartocel.dat tempchart -ascii

end

% end of function

%MATLAB code to write a temperature file in a chart.

%main script file.

explainprogram

[minimum, maximum] = mintomaxtemp;

charttempertaure(minimum, maximum)

% end of file

Save the MATLAB script with name, charttempertaure.m and main.m in the current folder. Execute the script by typing the script name at the command window to generate output.

Result:

MATLAB: A Practical Introduction to Programming and Problem Solving, Chapter 6, Problem 22E , additional homework tip  3

Therefore, the result is stated above.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Knowledge Booster
Background pattern image
Statistics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, statistics and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Trigonometry (MindTap Course List)
Trigonometry
ISBN:9781337278461
Author:Ron Larson
Publisher:Cengage Learning
Text book image
College Algebra
Algebra
ISBN:9781337282291
Author:Ron Larson
Publisher:Cengage Learning
Text book image
Holt Mcdougal Larson Pre-algebra: Student Edition...
Algebra
ISBN:9780547587776
Author:HOLT MCDOUGAL
Publisher:HOLT MCDOUGAL
Text book image
Trigonometry (MindTap Course List)
Trigonometry
ISBN:9781305652224
Author:Charles P. McKeague, Mark D. Turner
Publisher:Cengage Learning
Text book image
Algebra: Structure And Method, Book 1
Algebra
ISBN:9780395977224
Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. Cole
Publisher:McDougal Littell
Text book image
Mathematics For Machine Technology
Advanced Math
ISBN:9781337798310
Author:Peterson, John.
Publisher:Cengage Learning,
Finding Local Maxima and Minima by Differentiation; Author: Professor Dave Explains;https://www.youtube.com/watch?v=pvLj1s7SOtk;License: Standard YouTube License, CC-BY