
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
- An electronics company manufactures batches of n circuit boards. Before a batch is approved for shipment, m boards are randomly selected from the batch and tested. The batch is rejected if more than d boards in the sample are found to be faulty. a) A batch actually contains six faulty circuit boards. Find the probability that the batch is rejected when n = 20, m = 5, and d = 1. b) A batch actually contains nine faulty circuit boards. Find the probability that the batch is rejected when n = 30, m = 10, and d = 1.arrow_forwardTwenty-eight applicants interested in working for the Food Stamp program took an examination designed to measure their aptitude for social work. A stem-and-leaf plot of the 28 scores appears below, where the first column is the count per branch, the second column is the stem value, and the remaining digits are the leaves. a) List all the values. Count 1 Stems Leaves 4 6 1 4 6 567 9 3688 026799 9 8 145667788 7 9 1234788 b) Calculate the first quartile (Q1) and the third Quartile (Q3). c) Calculate the interquartile range. d) Construct a boxplot for this data.arrow_forwardPam, Rob and Sam get a cake that is one-third chocolate, one-third vanilla, and one-third strawberry as shown below. They wish to fairly divide the cake using the lone chooser method. Pam likes strawberry twice as much as chocolate or vanilla. Rob only likes chocolate. Sam, the chooser, likes vanilla and strawberry twice as much as chocolate. In the first division, Pam cuts the strawberry piece off and lets Rob choose his favorite piece. Based on that, Rob chooses the chocolate and vanilla parts. Note: All cuts made to the cake shown below are vertical.Which is a second division that Rob would make of his share of the cake?arrow_forward
- Three players (one divider and two choosers) are going to divide a cake fairly using the lone divider method. The divider cuts the cake into three slices (s1, s2, and s3). If the choosers' declarations are Chooser 1: {s1 , s2} and Chooser 2: {s2 , s3}. Using the lone-divider method, how many different fair divisions of this cake are possible?arrow_forwardTheorem 2.6 (The Minkowski inequality) Let p≥1. Suppose that X and Y are random variables, such that E|X|P <∞ and E|Y P <00. Then X+YpX+Yparrow_forwardTheorem 1.2 (1) Suppose that P(|X|≤b) = 1 for some b > 0, that EX = 0, and set Var X = 0². Then, for 0 0, P(X > x) ≤e-x+1²² P(|X|>x) ≤2e-1x+1²² (ii) Let X1, X2...., Xn be independent random variables with mean 0, suppose that P(X ≤b) = 1 for all k, and set oσ = Var X. Then, for x > 0. and 0x) ≤2 exp Σ k=1 (iii) If, in addition, X1, X2, X, are identically distributed, then P(S|x) ≤2 expl-tx+nt²o).arrow_forward
- Theorem 5.1 (Jensen's inequality) state without proof the Jensen's Ineg. Let X be a random variable, g a convex function, and suppose that X and g(X) are integrable. Then g(EX) < Eg(X).arrow_forwardCan social media mistakes hurt your chances of finding a job? According to a survey of 1,000 hiring managers across many different industries, 76% claim that they use social media sites to research prospective candidates for any job. Calculate the probabilities of the following events. (Round your answers to three decimal places.) answer parts a-c. a) Out of 30 job listings, at least 19 will conduct social media screening. b) Out of 30 job listings, fewer than 17 will conduct social media screening. c) Out of 30 job listings, exactly between 19 and 22 (including 19 and 22) will conduct social media screening. show all steps for probabilities please. answer parts a-c.arrow_forwardQuestion: we know that for rt. (x+ys s ا. 13. rs. and my so using this, show that it vye and EIXI, EIYO This : E (IX + Y) ≤2" (EIX (" + Ely!")arrow_forward
- Theorem 2.4 (The Hölder inequality) Let p+q=1. If E|X|P < ∞ and E|Y| < ∞, then . |EXY ≤ E|XY|||X|| ||||qarrow_forwardTheorem 7.6 (Etemadi's inequality) Let X1, X2, X, be independent random variables. Then, for all x > 0, P(max |S|>3x) ≤3 max P(S| > x). Isk≤narrow_forwardTheorem 7.2 Suppose that E X = 0 for all k, that Var X = 0} x) ≤ 2P(S>x 1≤k≤n S√2), -S√2). P(max Sk>x) ≤ 2P(|S|>x- 1arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- 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




