
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
- Answer this statistics and probability question without using AI tool.arrow_forwardedu/courses/106252/assignments/1102408?module_item_id=4856656 h Question 15 The numbers of false fire alarms were counted each month at a number of sites. The results are given in the following table. Month January February Number of False Alarms 45 41 March 25 April 26 May 45 June 32 July 43 August 40 September 34 October 25 November 33 39 December Click Download CSV to download csv file of data or copy/paste the data into Excel. After downloading the file, you may want to save it as an Excel Workbook. Test the hypothesis that false alarms are equally likely to occur in any month. Use 1% level of significance. Procedure: Select an answer What is the total count (that is, total number of false alarms counted): If false alarms are equally likely to occur in any month of 12 months, then what is the expected number of false alarms to occur in any month from the total false alarms of the year (Rounded to 3 or more decimal places): Assumptions: (select everything that applies) Normal…arrow_forwardA school administrator wants to see if there is a difference in the number of students per class for the Portland Public School district (Group 1) compared to the Beaverton School district (Group 2). Let μ be the average number of students per class for the Portland Public School district. Let 2 be the average number of students per class for the Beaverton School district. Assume the populations are normally distributed. A random sample of 25 Portland classes found a mean of 36 students per class with a standard deviation of 6. A random sample of 27 Beaverton classes found a mean of 38 students per class with a standard deviation of 5. a. Find a 91% confidence interval for the difference of the means. Use Excel Two Means Calculator found in the Course and round answers to 2 decimal places. <1-2 b. Select the correct conclusion based on the above confidence interval. O Since the above confidence interval contains zero, with 91% confident, it is plausible that the average number of…arrow_forward
- Show all working as to how the answer was derived. 1. Currently, bank employees in the United States On less than $2,000/month. How would you set up a hypothesis test to corroborate this statement based on a given sample and confidence level? A. Ho: <2000 B. Ho: ≤2000 c. H₁: <2000 D. H₁: ≤2000 Assuming that the number of customer complaints follows a normal distribution, test the hypothesis that the average number of complaints is higher in the Mexican franchise (remember to first conduct a test for the equality of variances to find the statistic to use in the test of means). Use a significance level of 5% for your calculations. A. This is a left-tailed test where the test statistic t = -1.4558 allows us to reject Ho. B. This is a right-tailed test where the test statistic t = -1.4201 allows us to reject H. C. This is a left-tailed test where the test statistic t = -1.4558 does not allow us to reject Ho- D. This is a left-tailed test where the test statistic t = -1.4201 does not allow…arrow_forwardShow all workings as to how the correct answer' was derived 4. Consider a large population of people from which a sample of 600 is taken and each is classified according to X = Nivel de educación (no education, primary education, secondary education, post-secondary education) and Y = Sexo (male or female). Conducting a test on the independence of the two qualitative variables (unit 5): 5. 6. Based on a past sample of 300 customers, a coffee pod factory found that 75% of its customers prefer the standard variety of coffee, while 25% prefer decaffeinated. However, it is suspected that in recent years there has been a change in customer preferences. To analyze whether this is, in fact, the case, the records of 250 customers who recently made a purchase are taken, obtaining the following results: Male Female Standard variety Decaf Number of clients 207 No education 15 30 Primary education 120 150 Secondary 90 90 education Post-secondary education 65 40 A. The null hypothesis is rejected,…arrow_forwardA group of 13 healthy children and adolescents participated in a phycological study designed to analyze the relationship between age and average total sleep time (ATST). To obtain a measure for ATST (in minutes), recordings were taken on each subject on three consecutive nights and then averaged. Results are provided to you in Sleep&Age.xlsx ✓ file. 1. (2 points) Determine the least-squares regression line for predicting average total sleep time using age. 2. (2 points) Make a scatter plot of the data with ATST on the y-axis (vertical axis) and Age on the x- axis (horizontal axis) with least squares regression line overlaid on the top (i.e.: obtain the fitted line plot). Make sure to attach the plot below. 3. (7 points) Check the assumptions for the simple linear regression. Attach any plots you used check the assumptions and comment on them. 4. (7 points) We want to see if the average sleep time decreases as the children grow older. Write the appropriate null and alternative…arrow_forward
- Question 3 14 pts Refer to output from Question 1 to answer the following. a) (9 points) Use the output information to conduct a statistical test of the research hypothesis that for this diet preparation and length of study, there is a direct (positive) linear relationship between weight gain and amount of lysine eaten. Use a 5% level of significance. b) (5 points) Calculate a 95% confidence interval for the slope and provide an interpretation of this interval.arrow_forwardSuppose we are interested in purchasing a multi-functioning inkjet printer. We want to see how the performance factors related to the price of the printer. Collected data from 20 printers include below information. PPM: Printing rate (pages per minutes) for a set of print jobs Price: Typical retail price (in dollars) at the time of the review. Data is not provided to you, but the default MINITAB output is provided to you. As you can see it is a partial output where you have to do some calculations using the provided information. Use the provided output to answer below questions. Regression Analysis: Price versus PPM Analysis of Variance DF Adj SS Adj MS F-Value P-Value Source Regression 1 PPM 1 74540 74540 74540 74540 21.75 0.000 21.75 0.000 Error 18 Lack-of-Fit 11 44191 Pure Error 7 17506 61697 3428 4017 2501 161 0.271 Total 19 136237 Model Summary S 58.5457 R-sq R-sq(adj) R-sq(pred) 54.71% 52.20% 42.25% Coefficients Term Coef SE Coef T-Value Constant PPM -94.2 90.9 56.4 -1.67 P-Value…arrow_forwardPlease Answer Question 3arrow_forward
- Please answer Question 5arrow_forwardPlease answer Question 2arrow_forwardA researcher is interested in studying how age (in years) associates with resting heart rate (beats per minutes) of adult men. He recruited 35 adult men and recorded their age and measured the resting heart rate (RHR). The researcher is specially interested in understanding whether the resting heart rate of older men is higher. Below MINITAB outputs are provided to you. Output 1 Output 2 Regression Equation RHR 67.89 +0.1576 Age Coefficients Regression Equation Age -78.8 +1.480 RHR Term Coef SE Coef T-Value P-Value VIF Coefficients Constant 67.89 1.42 47.90 0.000 Age 0.1576 0.0497 3.17 0.003 1.00 Term Constant -78.8 RHR 1.480 Coef SE Coef T-Value P-Value VIF 33.8 -2.33 0.467 3.17 0.026 0.003 1.00 Model Summary S R-sq R-sq(adj) R-sq(pred) 0.811306 23.33% 21.01% 13.11% Analysis of Variance Source DF Adj SS Adj MS F-Value P-Value Model Summary S R-sq R-sq(adj) R-sq(pred) 2.48678 23.33% 21.01% Analysis of Variance 10.93% Regression 1 6.609 6.6094 10.04 0.003 Source DF Adj SS Adj MS F-Value…arrow_forward
Trigonometry (MindTap Course List)TrigonometryISBN:9781337278461Author:Ron LarsonPublisher:Cengage Learning
Elementary AlgebraAlgebraISBN:9780998625713Author:Lynn Marecek, MaryAnne Anthony-SmithPublisher:OpenStax - Rice University
College 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




