
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
- Search A random sample of n₁ =217 people who live in a city were selected and 107 identified as a "student". A random sample of n₂ =109 people who live in a rural area were selected and 66 identified as a "student". Find the 98% confidence interval for the difference in the proportion of people that live in a city who identify as a "student" and the proportion of people that live in a rural area who identify as a "student." a. The point estimate for difference in population proportions (City group minus Rural Area group) = Round answers to 3 decimal places. -0.112 b. Fill in the blanks of the following statement. Round answers to 3 decimal places. We are 98 0% confident that the difference in population proportion of people who identified as a "student" in city and rural area falls between -0.247 0.022 0.022 and c. Select the correct conclusion based on the above confidence interval. O Since the above confidence interval gives only negative values, we have 98% confident that the…arrow_forwardCould you please provide solutions to the follwoing questions.Thanksarrow_forwardsearch A random sample of ni A random sample of n₂ "student". 217 people who live in a city were selected and 107 identified as a "student". 109 people who live in a rural area were selected and 66 identified as a Find the 98% confidence interval for the difference in the proportion of people that live in a city who identify as a "student" and the proportion of people that live in a rural area who identify as a "student." a. The point estimate for difference in population proportions (City group minus Rural Area group) = Round answers to 3 decimal places. -0.112 b. Fill in the blanks of the following statement. Round answers to 3 decimal places. We are 98 0% confident that the difference in population proportion of people who identified as a "student" in city and rural area falls between -0.247 ✔and 0.022 0.022 c. Select the correct conclusion based on the above confidence interval. Since the above confidence interval gives only negative values, we have 98% confident that the…arrow_forward
- Could you please help me answer parts b,d and e. Thanksarrow_forwardה The state of CT claims that the average time on death row is 15 years. A random survey of 75 death row inmates revealed that the average length of time on death row is 17.7 years with a standard deviation of 6.2 years. Conduct a hypothesis to test the state of CT's claim. What type of test should be run? t-test of a mean Oz-test of a proportion The alternative hypothesis indicates a two-tailed test O right-tailed test O left-tailed test Calculate the p-value. (Round properly to 4 decimal places) What is the decision? O We fail to reject the claim that the average time on death row is 15 years We reject the claim that the average time on death row is 15 years Submit Question F4 F3 F2 W E 14 POS UP T DELL F5 F6 F7 F8 F9 F10 F11 711 5 dos % $ 54 Οι 6 R T Y & 7arrow_forwardDon't answer without proper knowledge of this statistics and probability question.arrow_forward
- I need help in this statistics question don't answer without proper knowledge.arrow_forwardPx in decimal or integer value?arrow_forwardCounting Rules: a. The PSU's Mixed Me club has 32 members. You need to pick a different person for each of the following positions: president, treasurer, and secretary from the 32 members. How many different ways can you do this? b. How many ways can you choose 6 cookies from a cookie jar containing 16 cookies of all the same type? c. How many ways can you make a 6 digit password that can be any number (including zero) or letter (not case sensitive)? d. How many ways can you order 4 people standing in line? Check Answerarrow_forward
- Suppose a small company that manufactures cereal bars own two scales that weigh their products (say A and B). Quality control manager in this company is concerned that scale A is erroneous. He takes a sample of 20 cereal bars and weigh each of them using both scales A and B. Assume that you were given a spread sheet that include weights of the 20 cereal bars reported by two scales. Explain how you would approach testing the QC managers’ concern. What type of tests/CI you would construct to help him make a decision? Mention of any assumptions you would check or any graphing techniques you would use to display the data.arrow_forwardMatch the name of the sampling method descriptions given. choosing every 5th person on a list Situations separating all students by grade level, and selecting 10 students from each grade pulling 50 names from a hat randomly select two tables in the cafeteria and survey all the people at those two tables ask all the students in your math class Sampling Method a. Stratified b. Simple Random c. Convenience d. Systematic e. Cluster Submit Question II F3 <40 F4 144 $ F5 114 UP T DELL F6 F7 F8 F9 % olo &arrow_forwardthis question below Are 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 189 eight-year olds diagnosed with ASD out of 19300 eight-year olds evaluated. D Assume data were then collected for a fairly rural state and they found 70 eight-year olds diagnosed with ASD out of 2841 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 4% level b.) Compute a 96% 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? P1…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




