
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 21E
Solution:
The function file is,
% MATLAB code to calculate the side length of the triangle.
%function file.
function [out] = sidetriangle(x1, y1, x2, y2)
%define the side of the triangle by using the function sidetriangle.
out = sqrt((x1-x2)^2+(y1-y2)^2);
end
% end of function
%The script file should be placed in the same folder.
The function file to calculate the area is,
% MATLAB code to calculate the area of the triangle and print the result.
%function file.
function areatriangle(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.
area = sqrt (s*(s-a)*(s-b)*(s-c));
fprintf('Area of the triangle is %3.2f\n', area);
%print the area of the triangle.
end
% end of function
%The script file should be placed in the same folder.
The script file is,
% MATLAB code to calculate the area of the triangle by calling a function.
%script file.
point1 = input('the coordinates of the fist point is entered:');
%enter the coordinates of the first point.
point2 = input('the coordinates of the second point is entered:');
%enter the coordinates of the second point.
point3 = input('the coordinates of the third point is entered:');
%enter the coordinates of the third point.
x1 = point1(1);y1 = point1(2);
%define the variable x1.
x2 = point2(1);y2 = point2(2);
%define the variable x2.
x3 = point3(1);y3 = point3(2);
%define the variable x3.
areatriangle(x1, y1, x2, y2, x3, y3)
% end of file
%The script file should be placed in the same folder.
Explanation of Solution
The given two points are
The formula for 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:
clc
clear all
close all
% MATLAB code to calculate the side length of the triangle.
%function file.
function [out] = sidetriangle(x1, y1, x2, y2)
%define the side of the triangle by using the function sidetriangle.
out = sqrt((x1-x2)^2+(y1-y2)^2);
end
% end of function
%The script file should be placed in the same folder.
% MATLAB code to calculate the area of the triangle and print the result.
%function file.
function areatriangle(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.
area = sqrt (s*(s-a)*(s-b)*(s-c));
fprintf('Area of the triangle is %3.2f\n', area);
%print the area of the triangle.
end
% end of function
%The script file should be placed in the same folder.
% MATLAB code to calculate the area of the triangle by calling a function.
%script file.
point1 = input('the coordinates of the fist point is entered:');
%enter the coordinates of the first point.
point2 = input('the coordinates of the second point is entered:');
%enter the coordinates of the second point.
point3 = input('the coordinates of the third point is entered:');
%enter the coordinates of the third point.
x1 = point1(1);y1 = point1(2);
%define the variable x1.
x2 = point2(1);y2 = point2(2);
%define the variable x2.
x3 = point3(1);y3 = point3(2);
%define the variable x3.
areatriangle(x1, y1, x2, y2, x3, y3)
% end of file
%The script file should be placed in the same folder.
Save the MATLAB scripts with names, sidetriangle.m, areatriangle.m and areacall.m in the current folder. Execute the script by typing the script name at the command window to generate result.
Result:
The results are,



Therefore, the results and script files are stated above.
Want to see more full solutions like this?
Chapter 6 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Question 9 < 0/2 pts 299 Details cor 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 Number of False Alarms 31 February 37 March 39 April 41 May 44 June 29 July 45 August 40 September 44 October 27 35 29 November 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 10% 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) Random sample Normal populations Observed count for…arrow_forwardor Search Do the needs of patients in the emergency room differ for those who come by car vs. those by ambulance? Of the randomly selected emergency room patients who came by car 62 had an injury, 48 were sick, 49 had heart problems and 53 had other needs. Of the randomly selected emergency room patients who came by ambulance 48 had an injury, 29 were sick, 52 had heart problems and 28 had other needs. Conduct the appropriate hypothesis test using an a = 0.10 level of significance. a. What is the correct statistical test to use? O Goodness-of-Fit O Homogeneity O Independence O Paired t-test b. What are the null and alternative hypotheses? Ho: O Means of transportation to the emergency room and emergency room needs are independent. O Means of transportation to the emergency room and emergency room needs are dependent. O The distribution of emergency room needs for patients who come by car is not the same as it is for patients who come by ambulance. O The distribution of emergency room…arrow_forwardDiagonalize the following matrix. The real eigenvalues are given to the right of the matrix. 4 -42 22 2λ=2,4 4-86 Select the correct choice below and, if necessary, fill in the answer box to complete your choice. A. 200 For P = D= 0 4 0 0 0 4 (Simplify your answer.) B. 200 For P = D= 0 20 004 (Simplify your answer.) C. The matrix cannot be diagonalized.arrow_forward
- Diagonalize the following matrix. The real eigenvalues are given to the right of the matrix. 2 1 -1 -1 4-1=3,4 1 -1 4 Select the correct choice below and, if necessary, fill in the answer box to complete your choice. 300 A. 1 -16 For P = 1 02 D = 0 3 0 0 1 1 0 0 4 (Simplify your ans r.) B. 300 For P = D= 040 004 (Simplify your answer.) ○ C. The matrix cannot be diagonalized.arrow_forwardctor es ces If need help after the second attempt to this question, click Show Detailed Solution button below for formula and a similar problem. A researcher believes a new diet will have a positive impact on the health of adult lab mice but the effects on the weight of the mice are unknown. A sample of 10 mice was obtained and the mice were weighed before and after the diet treatment. Listed below are the measurement results: Click this button to reveal the data. Click again to collapse it. Mouse Before(g) After(g) Difference(g) 1 34.2 33.4 0.8 2 35 34.7 0.3 3 34.4 34.9 -0.5 35.9 34.4 1.5 5 33.2 32.8 0.4 6 35.8 34.5 1.3 7 35.4 35.6 -0.2 8 34.2 33.1 1.1 9 38.2 38.3 -0.1 10 34.8 33.9 0.9 Click this button to reveal the summary of data. Click again to collapse it. Before(g) After(g) Difference(g) Average Standard deviation 35.11 1.36 34.56 1.57 0.55 0.68 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…arrow_forwardA food-frequency questionnaire is used to measure dietary intake. The respondent specifies the number of servings of various food items they consumed over the previous week. The dietary cholesterol is then quantified for each respondent. The researchers were interested in assessing if there was an association between dietary cholesterol intake and high blood pressure. In a large sample of individuals who had completed the questionnaire, 250 persons with a high dietary cholesterol intake (greater than 300 mg/day) were selected and 250 persons with a low dietary cholesterol intake (less than 300 mg/day) were selected. The 500 selected participants had their medical history taken and were classified as having normal or high blood pressure. The data are given here. Blood Pressure Dietary Cholesterol High Total Low High 159 91 250 Low 78 172 250 Total 237 263 500 Test 2: two-tailed test for comparing two independent proportions 1. Clearly state the null and alternative hypothesis 2.…arrow_forward
- Test 1: Chi-Square test for independence Clearly state the null and alternative hypothesis Calculate the test statistic and p value. Show all your work for calculating the test statistic and probability statement for p-value. You may use MINITAB to get the final value of test statistic and p value and you must attach any MINITAB outputs) State the final conclusion at 5% significance levelarrow_forwardor Testing a claim about a population mean: t-Test An overly involved "neighborhood watch" group has been investigating the length of lawns. In years past, lawns had been mowed to a mean length of 2.4 inches. A recent random sample of lawn lengths is given below. Conduct an appropriate test, at a 5% significance level, to determine if the overall mean lawn length is now higher than 2.4 inches. Data (lawn lengths, measured in inches): 4.35 3.73 3.35 2.75 2.96 1.97 2.02 3.68 3.61 3.87 3.92 4.50 3.66 3.60 3.01 4.34 4.23 4.95 2.97 Checksum: 67.47 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. A. Consider the parameter of interest and choose the correct alternative hypothesis. Ομ = 2.4 Ο μ > 2.4 Op 2.4 Ομ < 2.4 Ομ Σ 2.4 Ομ 5 2.4 B. Are the necessary conditions present to carry out this inference procedure? Explain in context. Yes. Our sample was not larger than 30 in size, but the…arrow_forwardProctor ents ources Sources button below for formula and a similar problem. A researcher believes a new diet will have a positive impact on the health of adult lab mice but the effects on the weight of the mice are unknown. A sample of 10 mice was obtained and the mice were weighed before and after the diet treatment. Listed below are the measurement results: Click this button to reveal the data. Click again to collapse it. Mouse Before(g) After(g) Difference(g) 1 37.8 37.5 0.3 2 38.2 37.6 0.6 3 36.6 35.2 1.4 4 36.6 35.4 1.2 5 37.6 37.1 0.5 6 38.1 37.3 0.8 7 36.4 35 1.4 8 35.9 34.6 1.3 9 35.3 34.9 0.4 10 40.1 39.2 0.9 Click this button to reveal the summary of data. Click again to collapse it. Average Standard deviation Before(g) After(g) Difference(g) 37.26 1.39 36.38 1.55 0.88 0.42 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. Use 5% level of significance to decide whether…arrow_forward
- Does 10K running time increase when the runner listens to music? Nine runners were timed as they ran a 10K with and without listening to music. The running times in minutes are shown below. With Music Without Music Running Time 57 40 39 60 58 47 50 42 45 58 36 39 51 56 50 52 41 41 Assume a Normal distribution. What can be concluded at the the a 0.10 level of significance? For this study, we should use t-test for the difference between two dependent population means o search a. The null and alternative hypotheses would be: Houd 0 (please enter a decimal) H₁ ud 0 (Please enter a decimal) b. The test statistic = (please show your answer to 3 decimal places.) c. The p-value (Please show your answer to 4 decimal places.) d. The p-value is >v a e. Based on this, we should fail to reject f. Thus, the final conclusion is that ... the null hypothesis. The results are statistically significant at a = 0.10, so there is sufficient evidence to conclude M365 UP T DOLLarrow_forwardQuestion 5 10 pts 1 Details A college administrator claims that 80% of college students purchase their books from the campus bookstore. You this is inaccurate and form a random sample of 57 students at that college and find that 36 of them purchased their books from the bookstore. Test the administrator's claim using a level of significance of 1%. a. What type of test will be used in this problem? A test for a proportion b. What evidence justifies the use of this test? Check all that apply np5 and nq > 5 The population standard deviation is not known The original population is approximately normal There are two different samples being compared The sample size is larger than 30 The sample standard deviation is not known The population standard deviation is known c. Enter the null hypothesis for this test. Ho p 0.80 d. Enter the alternative hypothesis for this test. H₁p 0.80 e. Is the original claim located in the null or alternative hypothesis? Null Hypothesis f. What is the test…arrow_forwardAre there less children diagnosed with Autism Spectrum Disorder (ASD) in states that have larger urban areas over states that are mostly rural? Assume data were collected from a fairly urban state and they found 195 eight-year olds diagnosed with AGD out of 18183 eight-year olds evaluated. Assume data were then collected for a fairly rural state and they found 54 eight-year olds diagnosed with AGD out of 2179 eight-year olds evaluated. is there enough evidence to show that the proportion of children diagnosed with ASD in the fairly urban state is lower than the proportion in the fairly rural state? a.) Test at the 3% level b.) Compute a 97% confidence interval for the difference in proportions. Use the following steps for the hypothesis test. For the confidence interval you do not need to do all the steps since you did some of them already in hypothesis test. Part a.) HYPOTHESIS TEST Parameter What is the correct parameter symbol and wording for population 1? P The proportion of all…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




