
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
- Square matrices with entries +1 and -1 with largest determinant appear in several applications. We have not yet defined determinant but that is not relevant here. See the text Chapter 3 introductory example for an application of these matrices to an accurate weighing schemes for multiple small objects. These also are related to Reed-Muller error correcting codes used to communicate with early spacecraft sent to Mars and to Hadamard designs used in design of statistical experiments. It turns out that these matrices have entries +1 and -1 and each pair of columns orthogonal. They are called Hadamard matrices. Their size must be 2 × 2 or n x n where n is a multiple of 4. It is conjectured that they exist for all multiples of 4 but this is not solved. A 2 × 2 Hadamard matrix is H2 using blocks that are H₂ is 1 = } ] and a 4 x 4 Hadamard matrix formed 1 1 1 1 H2 H2 1 −1 1 -1 H4 = H2 -H2 -1 −1 1 From the description above and orthogonality, we formally define a Hadamard matrix of order n as…arrow_forwardFor matrix A assume that (ATA)-¹ exists. The projection matrix onto the column space of A is P = A(ATA)-¹AT. (We haven't defined column space yet but that is not needed here.) (a) Prove that P² = P. = = = (b) Prove that for all 6, Añ 6 has a solution & if and only if P₁ = 6 has a solution 7. That is show that if there exists a ū such that Pu 6 then there exists a v such that Av 6 and conversely show that if there exists a v such that Av = 6 then there exists a ū such that Pū = b. Use the given information to describe a v in terms of u and A that 'works' and for the converse describe a ū in terms of 7 and A that 'works'.arrow_forwardFor both of the following make use of the matrix multiplication definition: If A is m × n and B is n xp then (AB)ij = Σ=1(A)ik (B)kj. (a) The trace of a square matrix is the sum of its diagonal elements. Writing Tr(A) for the trace of an n × n matrix this is Tr(A) = 1 A. Prove that Tr(AB) = Tr(BA). Assume that A is m × n, then B is n × m in order for both to be defined. (b) If L and M are n×n lower triangular matrices, prove that the product LM is lower triangular. A matrix A is lower triangular if (A)ij O whenever j > i. =arrow_forward
- 17?module_item_id=4856618 was.pdx. Given = 0.1714 and n = 35 for the high income group, Test the claim that the proportion of children in the high income group that drew a picture of the nickel too large is smaller than 50%. Test at the 0.03 significance level. a. Identify the correct alternative hypothesis: Op = .50 Op.50 Oμ=.50 Op>.50 Op <.50 b. The test statistic formula set up with numbers is as follows: Provide all the decimal places. p-P x= = p-(1-p) 16 (1- ))/) The final answer for the test statistic from technology (Excel or Ti Calculator functions NOT from the above formula) is as follows: Round to 4 decimal places. x = c. Using the P-value method, the P-value is: Round to 4 decimal places. d. Based on this, we O Reject Ho O Fail to reject Ho e. Which means O There is not sufficient evidence to support the claim O There is not sufficient evidence to warrant rejection of the claim O There is sufficient evidence to warrant rejection of the claim O The sample data supports the…arrow_forwardTest the claim that the proportion of people who own cats is smaller than 20% at the 0.025 significance level. The first HELP video explains how to do a similar problem on Ti Calculator and the second HELP video shows how to use Excel Calculator for a similar problem. The null and alternative hypothesis would be: Ho p=0.2 Ho p=0.2 Ho: p=0.2 Ho p=0.2 Ho: Ha p0.2 Ha p>0.2 Ha p>0.2 Ha: p<0.2 Ha: о о о 0.2 Ho: p=0.2 <0.2 Ha: 0.2 о The test is: right-tailed two-tailed left-tailed Based on a sample of 800 people, 14% owned cats The p-value is: Based on this we: O Fail to reject the null hypothesis O Reject the null hypothesis Question Help: Video 1 Video 2 Submit Question E F3 F4 LL E ° M365 14 $ (to 2 decimals) UP T 合 D DELL Channel Deta F5 F6 F7 F8 F9 F10 P 205 % 6 & 87 * 8 RT Y Darrow_forwardWhat is the detailed solution for question and answer 7c? How to get the frequency densities of 98 and 15?arrow_forward
- I need help in this question properly . I need help in this statistics question.arrow_forwardWhat is the explanation of the solution and answer to the problem: Boxes of floor tiles are to be offered for sale at a special price of $75. The boxes claim to contain at least 100 tiles each. b. How may the seller benefit if the numbers 12,16,7,8,21,4,11,6,5 and 10 are used to draw the stem-and-leaf diagram instead of the actual numbers of tiles? Answer: Seller may notice that 10+16+7+8+21+4+11+6+5+10=100,which means that 11 (rather than ten) boxes of 100 tiles could be offered for sale.arrow_forwardWhat is the explanation of the solution and answer to the problem: Boxes of floor tiles are to be offered for sale at a special price of $75. The boxes claim to contain at least 100 tiles each. b. How may the seller benefit if the numbers 12,16,7,8,21,4,11,6,5 and 10 are used to draw the stem-and-leaf diagram instead of the actual numbers of tiles? Answer: Seller may notice that 10+16+7+8+21+4+11+6+5+10=100,which means that 11 (rather than ten) boxes of 100 tiles could be offered for sale.arrow_forward
- Table Summary: A table with 5 rows and 5 columns. The columns are titled y and the column heads are 0, 1, 2, 3, and 4. The rows are titled X and the row heads are 0, 1, 2, 3, and 4. X 0 y 1 2 3 4 0 0.03 0.01 1 0.09 0.01 0.05 0.08 0.03 0.01 0.02 0.01 2 0.09 3 0.04 0.05 0.07 0.04 0.02 0.06 0.04 0.07 0.04 0.02 0.03 0.04 0.03 0.02 Refer to Exercise 9. a. Find μx+Y. b. Find σx+Y. c. Find P(X + Y = 5).arrow_forwardAssume that the cost of an engine repair is $50, and the cost of a transmission repair is $100. Let T represent the total cost of repairs during a one-hour time interval. y X 0 1 2 3 0 0.13 0.10 0.07 0.03 1 0.12 0.16 0.08 0.04 2 0.02 0.06 0.08 0.04 3 0.01 0.02 0.02 0.02 Find uT. Find σT. Find P (T=250).arrow_forwardFor continuous random variables X and Y with joint probability density function a. Find P(X > 1 and Y > 1). xe-(x+2y) f(x, y) = x > 0 and y > 0 0 otherwise b. Find the marginal probability density functions fx(x) and fy(y). c. Are X and Y independent? Explain.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




