Info

This question is locked. Rouvrir pour modifier ou répondre.

Confusion with triangles, area , perimeter

12 vues (au cours des 30 derniers jours)
Dylan
Dylan le 17 Fév 2014
Locked: John D'Errico le 27 Oct 2024 à 1:13
This is the problem I have. I have absolutely no idea where to start.
1. Write a MATLAB script called Triangle to calculate the perimeter P of the triangle A-B-C defined by the x and y coordinates of points A, B, and C as listed below.
The length of triangle side a = sqrt( (Bx – Cx)2 + ( By– Cy)2 ),
Where Bx and Cx are the x-coordinates of points B and C, and By and Cy are the y-coordinates of points B and C.
Therefore for the points shown below, length of side a = sqrt( (220 – 480)2 + ( 320 – 230)2 )
x y Point coordinates in feet: A ( 90 , 130 ) B ( 220 , 320 ) C ( 480 , 230 )
2. Add to the script a formula for calculating the area of the triangle

Réponses (1)

BhaTTa
BhaTTa le 26 Oct 2024 à 18:12
Hey @Dylan, I assume that you require a MATLAB script that calculates both the perimeter and the area of a triangle given the coordinates of its vertices, please refer to the code below:
% Define the coordinates of the points
Ax = 90; Ay = 130;
Bx = 220; By = 320;
Cx = 480; Cy = 230;
% Calculate the lengths of the sides using the distance formula
a = sqrt((Bx - Cx)^2 + (By - Cy)^2);
b = sqrt((Ax - Cx)^2 + (Ay - Cy)^2);
c = sqrt((Ax - Bx)^2 + (Ay - By)^2);
% Calculate the perimeter of the triangle
P = a + b + c;
% Calculate the semi-perimeter for Heron's formula
s = P / 2;
% Calculate the area using Heron's formula
Area = sqrt(s * (s - a) * (s - b) * (s - c));
% Display the results
fprintf('The perimeter of the triangle is: %.2f feet\n', P);
The perimeter of the triangle is: 907.97 feet
fprintf('The area of the triangle is: %.2f square feet\n', Area);
The area of the triangle is: 30550.00 square feet
  2 commentaires
Walter Roberson
Walter Roberson le 26 Oct 2024 à 19:06
We do not recommend posting complete code to answer homework questions.
John D'Errico
John D'Errico le 27 Oct 2024 à 1:13
You answered a homework question that is now 10 years old. Odds are the person posting the question does not have the least interest in what you did, as their homework assignment is now 10 years overdue.
regardless, please don't do homework questions with no effort made. It does not help the student, beyond teaching them to keep on posting homework questions with no effort made. It does not help the forum, as it convinces other students to also post their homework with no effort made.

This question is locked.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by