![MATLAB: A Practical Introduction to Programming and Problem Solving](https://www.bartleby.com/isbn_cover_images/9780128154793/9780128154793_smallCoverImage.jpg)
Concept explainers
To write:
• A program to call a
• 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.
![Check Mark](/static/check-mark.png)
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:
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
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:
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
The conversion formula is given as,
Substitute 190 for F in the above formula.
Substitute 200 for F in the above formula.
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:
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Examine the Variables: Carefully review and note the names of all variables in the dataset. Examples of these variables include: Mileage (mpg) Number of Cylinders (cyl) Displacement (disp) Horsepower (hp) Research: Google to understand these variables. Statistical Analysis: Select mpg variable, and perform the following statistical tests. Once you are done with these tests using mpg variable, repeat the same with hp Mean Median First Quartile (Q1) Second Quartile (Q2) Third Quartile (Q3) Fourth Quartile (Q4) 10th Percentile 70th Percentile Skewness Kurtosis Document Your Results: In RStudio: Before running each statistical test, provide a heading in the format shown at the bottom. “# Mean of mileage – Your name’s command” In Microsoft Word: Once you've completed all tests, take a screenshot of your results in RStudio and paste it into a Microsoft Word document. Make sure that snapshots are very clear. You will need multiple snapshots. Also transfer these results to the…arrow_forward2 (VaR and ES) Suppose X1 are independent. Prove that ~ Unif[-0.5, 0.5] and X2 VaRa (X1X2) < VaRa(X1) + VaRa (X2). ~ Unif[-0.5, 0.5]arrow_forward8 (Correlation and Diversification) Assume we have two stocks, A and B, show that a particular combination of the two stocks produce a risk-free portfolio when the correlation between the return of A and B is -1.arrow_forward
- 9 (Portfolio allocation) Suppose R₁ and R2 are returns of 2 assets and with expected return and variance respectively r₁ and 72 and variance-covariance σ2, 0%½ and σ12. Find −∞ ≤ w ≤ ∞ such that the portfolio wR₁ + (1 - w) R₂ has the smallest risk.arrow_forward7 (Multivariate random variable) Suppose X, €1, €2, €3 are IID N(0, 1) and Y2 Y₁ = 0.2 0.8X + €1, Y₂ = 0.3 +0.7X+ €2, Y3 = 0.2 + 0.9X + €3. = (In models like this, X is called the common factors of Y₁, Y₂, Y3.) Y = (Y1, Y2, Y3). (a) Find E(Y) and cov(Y). (b) What can you observe from cov(Y). Writearrow_forward1 (VaR and ES) Suppose X ~ f(x) with 1+x, if 0> x > −1 f(x) = 1−x if 1 x > 0 Find VaRo.05 (X) and ES0.05 (X).arrow_forward
- Joy is making Christmas gifts. She has 6 1/12 feet of yarn and will need 4 1/4 to complete our project. How much yarn will she have left over compute this solution in two different ways arrow_forwardSolve for X. Explain each step. 2^2x • 2^-4=8arrow_forwardOne hundred people were surveyed, and one question pertained to their educational background. The results of this question and their genders are given in the following table. Female (F) Male (F′) Total College degree (D) 30 20 50 No college degree (D′) 30 20 50 Total 60 40 100 If a person is selected at random from those surveyed, find the probability of each of the following events.1. The person is female or has a college degree. Answer: equation editor Equation Editor 2. The person is male or does not have a college degree. Answer: equation editor Equation Editor 3. The person is female or does not have a college degree.arrow_forward
- Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw HillAlgebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal Littell
- Holt Mcdougal Larson Pre-algebra: Student Edition...AlgebraISBN:9780547587776Author:HOLT MCDOUGALPublisher:HOLT MCDOUGALFunctions and Change: A Modeling Approach to Coll...AlgebraISBN:9781337111348Author:Bruce Crauder, Benny Evans, Alan NoellPublisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9780079039897/9780079039897_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781938168994/9781938168994_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780395977224/9780395977224_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780547587776/9780547587776_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337111348/9781337111348_smallCoverImage.gif)