MATLAB Chapter 7 UserDefined Functions and Functi 15 The are

MATLAB Chapter 7: User-Defined Functions and Functi 15. The area of a triangle ABC can be calculated by: where AB is the vector from point A to point B and AC is the vector from point A to point C. Write a user-defined MATLAB function that determines the area of a triangle given its vertices\' coordinates. For the function name and argu- ments, use [Area] = Tr!Area (A, B, C), The input arguments A, B, and C, are vectors, each with the coordinates of the corresponding vertex. Write the code of TriArea such that it has two subfunctions-one that determines the vec- tors AB and AC and another that executes the cross product. (If available, use the user-defined functions from Problem 14). The function should work for a triangle in the x-y plane (each vertex is defined by two coordinates) or for a triangle in space (each vertex is defined by three coordinates). Use the func- tion to determine the areas of triangles with the following vertices: (a) A = (1,2), B= (10,3),C= (6,11) (b) A = (-15,-42,-3), B (-51,63,2), C = (12.1, 0,-05) 16. Write a user-defined MATLAB function that determines the circumference of a triangle when the coordinates of the vertices are given. For the function name and arguments, use [cr] -cirtriangle (A, B, C). The input argu- ments A, B, C are vectors with the coordinates of the vertices, and the output

Solution

Ans 15)

function [Area] = TriArea(A,B,C)
if(size(A,2)==2)
A = [A,1];B = [B,1];C = [C,1]; % finxing the dimention if it is a 2-D coordinate
end
AB = A-B;
AC = A-C;
Area = (1/2)*norm(cross(AB,AC));
end

MULTIPLE QUESTIONS PLEASE SPLIT

 MATLAB Chapter 7: User-Defined Functions and Functi 15. The area of a triangle ABC can be calculated by: where AB is the vector from point A to point B and AC

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site