
Concept explainers
To write:
A script that will prompt the user to enter the coordinates of three points that determine a triangle, then calculate and print the area of the triangle and then call one

Answer to Problem 19E
Solution:
The script file is,
% MATLAB code to calculate the area of the triangle by calling a function.
%script file.
x1 = input('the x coordinate of the fist point is entered:');
%enter the x coordinate of the first point.
x2 = input('the x coordinate of the second point is entered:');
%enter the x coordinate of the second point.
x3 = input('the x coordinate of the third point is entered:');
%enter the x coordinate of the third point.
y1 = input('the y coordinate of the fist point is entered:');
%enter the y coordinate of the first point.
y2 = input('the y coordinate of the second point is entered:');
%enter the y coordinate of the second point.
y3 = input('the y coordinate of the third point is entered:');
%enter the y coordinate of the third point.
Area = trianglearea(x1, y1, x2, y2, x3, y3);
fprintf('The triangle’’s area is %.2f\n', Area)
% end of script file
%The script file should be placed in the same folder.
The function file is,
% MATLAB code to calculate the area of the triangle.
%function file.
function out = trianglearea(x1, y1, x2, y2, x3, y3)
%define the area of triangle by using the function areatriangle.
a = sidetriangle(x1, y1, x2, y2);
%define the variable a.
b = sidetriangle(x2, y2, x3, y3);
%define the variable b.
c = sidetriangle(x3, y3, x1, y1);
%define the variable c.
s = (a+b+c)/2;
%define the variable s.
out = sqrt (s*(s-a)*(s-b)*(s-c));
end
function out2 = sidetriangle(x1, y1, x2, y2)
%calculate the distnace between the two points by calling a function
%sidetriangle.
out2 = sqrt((x1-x2)^2 + (y1-y2)^2);
%calculate the sides of the triangle.
end
% end of function
%The function file should be placed in the same folder.
Explanation of Solution
The given two points are
The formula of the distance between the two points is given as,
Substitute 0 for
Consider the three points are
The side of the triangle is,
Substitute 0 for
The side of the triangle is,
Substitute 5 for
The side of the triangle is,
Substitute 5 for
The formula for half sum of the sides of the triangle is,
Substitute 5 for a, 5 for b and
The formula for the area of the triangle is,
Substitute 5 for a, 5 for b,
MATLAB Code:
% MATLAB code to calculate the area of the triangle by calling a function.
%script file.
x1 = input('the x coordinate of the fist point is entered:');
%enter the x coordinate of the first point.
x2 = input('the x coordinate of the second point is entered:');
%enter the x coordinate of the second point.
x3 = input('the x coordinate of the third point is entered:');
%enter the x coordinate of the third point.
y1 = input('the y coordinate of the fist point is entered:');
%enter the y coordinate of the first point.
y2 = input('the y coordinate of the second point is entered:');
%enter the y coordinate of the second point.
y3 = input('the y coordinate of the third point is entered:');
%enter the y coordinate of the third point.
Area = trianglearea(x1, y1, x2, y2, x3, y3);
fprintf('The triangle’’s area is %.2f\n', Area)
% end of script file
%The script file should be placed in the same folder.
% MATLAB code to calculate the area of the triangle.
%function file.
function out = trianglearea(x1, y1, x2, y2, x3, y3)
%define the area of triangle by using the function areatriangle.
a = sidetriangle(x1, y1, x2, y2);
%define the variable a.
b = sidetriangle(x2, y2, x3, y3);
%define the variable b.
c = sidetriangle(x3, y3, x1, y1);
%define the variable c.
s = (a+b+c)/2;
%define the variable s.
out = sqrt (s*(s-a)*(s-b)*(s-c));
end
function out2 = sidetriangle(x1, y1, x2, y2)
%calculate the distnace between the two points by calling a function
%sidetriangle.
out2 = sqrt((x1-x2)^2 + (y1-y2)^2);
%calculate the sides of the triangle.
end
% end of function
%The function file should be placed in the same folder.
Save the MATLAB script with name, mainscript.m, and the function file is trianglearea.m in the current folder. Execute the program by typing the script name at the command window to generate result.
Result:
The output is,
Therefore, the result is stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- 13. A pharmaceutical company has developed a new drug for depression. There is a concern, however, that the drug also raises the blood pressure of its users. A researcher wants to conduct a test to validate this claim. Would the manager of the pharmaceutical company be more concerned about a Type I error or a Type II error? Explain.arrow_forwardFind the z score that corresponds to the given area 30% below z.arrow_forwardFind the following probability P(z<-.24)arrow_forward
- 3. Explain why the following statements are not correct. a. "With my methodological approach, I can reduce the Type I error with the given sample information without changing the Type II error." b. "I have already decided how much of the Type I error I am going to allow. A bigger sample will not change either the Type I or Type II error." C. "I can reduce the Type II error by making it difficult to reject the null hypothesis." d. "By making it easy to reject the null hypothesis, I am reducing the Type I error."arrow_forwardGiven the following sample data values: 7, 12, 15, 9, 15, 13, 12, 10, 18,12 Find the following: a) Σ x= b) x² = c) x = n d) Median = e) Midrange x = (Enter a whole number) (Enter a whole number) (use one decimal place accuracy) (use one decimal place accuracy) (use one decimal place accuracy) f) the range= g) the variance, s² (Enter a whole number) f) Standard Deviation, s = (use one decimal place accuracy) Use the formula s² ·Σx² -(x)² n(n-1) nΣ x²-(x)² 2 Use the formula s = n(n-1) (use one decimal place accuracy)arrow_forwardTable of hours of television watched per week: 11 15 24 34 36 22 20 30 12 32 24 36 42 36 42 26 37 39 48 35 26 29 27 81276 40 54 47 KARKE 31 35 42 75 35 46 36 42 65 28 54 65 28 23 28 23669 34 43 35 36 16 19 19 28212 Using the data above, construct a frequency table according the following classes: Number of Hours Frequency Relative Frequency 10-19 20-29 |30-39 40-49 50-59 60-69 70-79 80-89 From the frequency table above, find a) the lower class limits b) the upper class limits c) the class width d) the class boundaries Statistics 300 Frequency Tables and Pictures of Data, page 2 Using your frequency table, construct a frequency and a relative frequency histogram labeling both axes.arrow_forward
- Table of hours of television watched per week: 11 15 24 34 36 22 20 30 12 32 24 36 42 36 42 26 37 39 48 35 26 29 27 81276 40 54 47 KARKE 31 35 42 75 35 46 36 42 65 28 54 65 28 23 28 23669 34 43 35 36 16 19 19 28212 Using the data above, construct a frequency table according the following classes: Number of Hours Frequency Relative Frequency 10-19 20-29 |30-39 40-49 50-59 60-69 70-79 80-89 From the frequency table above, find a) the lower class limits b) the upper class limits c) the class width d) the class boundaries Statistics 300 Frequency Tables and Pictures of Data, page 2 Using your frequency table, construct a frequency and a relative frequency histogram labeling both axes.arrow_forwardA study was undertaken to compare respiratory responses of hypnotized and unhypnotized subjects. The following data represent total ventilation measured in liters of air per minute per square meter of body area for two independent (and randomly chosen) samples. Analyze these data using the appropriate non-parametric hypothesis test. Unhypnotized: 5.0 5.3 5.3 5.4 5.9 6.2 6.6 6.7 Hypnotized: 5.8 5.9 6.2 6.6 6.7 6.1 7.3 7.4arrow_forwardThe class will include a data exercise where students will be introduced to publicly available data sources. Students will gain experience in manipulating data from the web and applying it to understanding the economic and demographic conditions of regions in the U.S. Regions and topics of focus will be determined (by the student with instructor approval) prior to April. What data exercise can I do to fulfill this requirement? Please explain.arrow_forward
- Consider the ceocomp dataset of compensation information for the CEO’s of 100 U.S. companies. We wish to fit aregression model to assess the relationship between CEO compensation in thousands of dollars (includes salary andbonus, but not stock gains) and the following variates:AGE: The CEOs age, in yearsEDUCATN: The CEO’s education level (1 = no college degree; 2 = college/undergrad. degree; 3 = grad. degree)BACKGRD: Background type(1= banking/financial; 2 = sales/marketing; 3 = technical; 4 = legal; 5 = other)TENURE: Number of years employed by the firmEXPER: Number of years as the firm CEOSALES: Sales revenues, in millions of dollarsVAL: Market value of the CEO's stock, in natural logarithm unitsPCNTOWN: Percentage of firm's market value owned by the CEOPROF: Profits of the firm, before taxes, in millions of dollars1) Create a scatterplot matrix for this dataset. Briefly comment on the observed relationships between compensationand the other variates.Note that companies with negative…arrow_forward6 (Model Selection, Estimation and Prediction of GARCH) Consider the daily returns rt of General Electric Company stock (ticker: "GE") from "2021-01-01" to "2024-03-31", comprising a total of 813 daily returns. Using the "fGarch" package of R, outputs of fitting three GARCH models to the returns are given at the end of this question. Model 1 ARCH (1) with standard normal innovations; Model 2 Model 3 GARCH (1, 1) with Student-t innovations; GARCH (2, 2) with Student-t innovations; Based on the outputs, answer the following questions. (a) What can be inferred from the Standardized Residual Tests conducted on Model 1? (b) Which model do you recommend for prediction between Model 2 and Model 3? Why? (c) Write down the fitted model for the model that you recommended in Part (b). (d) Using the model recommended in Part (b), predict the conditional volatility in the next trading day, specifically trading day 814.arrow_forward4 (MLE of ARCH) Suppose rt follows ARCH(2) with E(rt) = 0, rt = ut, ut = στει, σε where {+} is a sequence of independent and identically distributed (iid) standard normal random variables. With observations r₁,...,, write down the log-likelihood function for the model esti- mation.arrow_forward
- Trigonometry (MindTap Course List)TrigonometryISBN:9781337278461Author:Ron LarsonPublisher:Cengage LearningElementary AlgebraAlgebraISBN:9780998625713Author:Lynn Marecek, MaryAnne Anthony-SmithPublisher:OpenStax - Rice UniversityCollege AlgebraAlgebraISBN:9781305115545Author:James Stewart, Lothar Redlin, Saleem WatsonPublisher:Cengage Learning
- Holt Mcdougal Larson Pre-algebra: Student Edition...AlgebraISBN:9780547587776Author:HOLT MCDOUGALPublisher:HOLT MCDOUGALAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage




