Problem 2-Writing a function that determines the interior angles of a triangle,
ID: 3874577 • Letter: P
Question
Problem 2-Writing a function that determines the interior angles of a triangle, given the length of the sides. This problem will assume that the side lengths are valid and entered from shortest to longest. You will make use of the following equations: sin sin sin The first equation is the Law of Sines and the second equation is the Law of Cosines. These equations give the relationship between the length of the sides of a triangle, (i.e., A, B, and C) to the interior angles, (i.e. alpha, beta, and gamma) as shown in the following figure. Use the following instructions to help create your function . Open the editor window, and use the information discussed in class as a template to write your function. Name your function as described at the beginning of the lab instructions. *Include a comment block describing the function. . Have inputs of triangle side lengths of A, B, and C . Use the Law of Sines and Cosines to determine the angles, alpha, beta, and gamma in degrees. . Return the three angles as output. * Test your function in the command window to make sure it works as required. Include comments to document your function and your results. Include commented results at the conclusion of your function m-file for the case where A 2, B 3, and C 4, for the case where A-5, B-8, and C-15, and for the case where A = 0.25x10^ 3, B-0.4x10^ 3, and C-0.6x10^3 .To check your solution, does alpha +beta +gamma- 180?Explanation / Answer
Given below is the code for the question and output. Save the code in angles.m file. You can test the code as shown in the bottom and verify the sum of angles is 180.
Please do rate the answer if it was helpful. Thank you
File: angles.m
==============
function [alpha, beta, gamma] = angles(A, B, C)
%function to calculate angles of a triangle using law of sines and law of cosines
%input parameters A, B, C represent the sides of triangle
%output is list of angles [alpha, beta, gamma] representing the 3 angles in degrees
%use cosine law to find out gamma in radians
gamRadians= acos((A.^2 + B.^2 - C.^2) ./ (2 .* A .* B));
%use sine law to find alpha in radians
alpRadians = asin( A .* sin(gamRadians) ./ C);
%use sine law to find beta in radians
betRadians = asin( B .* sin(gamRadians) ./ C);
%convert all angles to degrees
alpha = alpRadians * 180 / pi;
beta = betRadians * 180 / pi;
gamma = gamRadians * 180 / pi;
end
======================
Testing
> [alpha, beta, gamma] = angles(3, 4, 5)
alpha = 36.870
beta = 53.130
gamma = 90
> [alpha, beta, gamma] = angles(2, 3, 4)
alpha = 28.955
beta = 46.567
gamma = 104.48
> [alpha, beta, gamma] = angles(0.25E3, 0.4E3, 0.6E3)
alpha = 17.612
beta = 28.955
gamma = 133.43
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.