Info
This question is locked. Vuélvala a abrir para editarla o responderla.
Confusion with triangles, area , perimeter
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
BhaTTa
el 26 de Oct. de 2024 a las 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);
fprintf('The area of the triangle is: %.2f square feet\n', Area);
2 comentarios
Walter Roberson
el 26 de Oct. de 2024 a las 19:06
We do not recommend posting complete code to answer homework questions.
John D'Errico
el 27 de Oct. de 2024 a las 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.
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!