
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
- Suppose that we have data y = (1,...,n). Each data point y; is assumed to be generated by a distribution with the following probability density function: P(yi | n)=3nye, y; ≥0. The unknown parameter is >0. (a) Write down the likelihood for n given y, and find an expression for the maximum likelihood estimate (MLE) of n. (b) A Gamma(a, 3) distribution is chosen as the prior distribution for 7, where a > 0 and > 0 are known. Show that the posterior distribution of n, denoted p(n | A), is also a gamma distribution with updated parameters that you should determine.arrow_forwardDo the data provide compelling evidence (at α=0.05) for concluding that true average strength for the 1078 grade exceeds that for the 1064 grade? Show all your work. Estimate the difference between true average strengths for the two grades with a 95% confidence interval for the previous problem.arrow_forwardUse Minitab and the GPA data (GPAData.xlsx) to answer the following. a) (15 points) Is there a mean difference in High School GPA and a person's GPA following their first year of college? State the relevant hypotheses and provide the p-value from the output. Include a decision and interpretation at a 10% level of significance. b) (5 points) Is the assumption of normality satisfied? Include any plots you make to check the normality assumption and comments on your observations.arrow_forward
 - A researcher wants to perform a hypothesis test to see if the mean salary of the faculty in private and public institutions are different. Random samples of 36 faculty from private and public institutions were selected. Salaries of the selected faculty from private and public institutions are provided to you in facultysalary.csv file. 1. Make side-by-side boxplots of the salaries for faculty in private and public institutions (In MINITAB, go to Graphs-- >Boxplot-->and explore the available options to see how to make a side-by-side boxplot of the data). 2. Comment on your observations from the side-by-side boxplot made in part 1. 3. Calculate the descriptive statistics: mean, standard deviation for the two samples and attach the MINITAB output. 4. When carrying out a hypothesis test to achieve the aforementioned goal, would you recommend using pooled variance approach or unpooled variance approach? Provide reasoning for your choice. 5. Regardless what you recommend in part 4, carry out…arrow_forwardDave Hughes owns a local restaurant. He wonders if a redesign of the menu will increase, on average, the amount customers spend when visiting his establishment. For the following scenario, pick a statistical method we discussed regarding comparing two groups that would be appropriate for analyzing the problem. a) Hughes records the mean sales the week before the change and the week after the change and then wonders whether the difference is statistically significant. [ Select ] b) Hughes randomly samples 100 people and shows both menus to each person, asking them to rate each menu from 0 (very poor) to 20 (excellent) and then wonders whether the difference is statistically significant. [ Select ] c) Hughes randomly samples 100 people and randomly separates them into two groups of 50. He asks those in group 1 to give a rating of ‘positive’ or ‘negative’ to the old menu and those in group 2 to give a rating of ‘positive’ or ‘negative’ to the new menu. He then computes the proportion of…arrow_forwardPlease don't answer of this statistics and probability question without knowledge.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




