Info

This question is locked. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Confusion with triangles, area , perimeter

16 Ansichten (letzte 30 Tage)
Dylan
Dylan am 17 Feb. 2014
Locked: John D'Errico am 27 Okt. 2024 um 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

Antworten (1)

BhaTTa
BhaTTa am 26 Okt. 2024 um 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 Kommentare
Walter Roberson
Walter Roberson am 26 Okt. 2024 um 19:06
We do not recommend posting complete code to answer homework questions.
John D'Errico
John D'Errico am 27 Okt. 2024 um 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.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by