Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

0 Figure 1: Triangle with three coordinates (xl, y1), (x2, y2), (x3, y3) Problem

ID: 3873948 • Letter: 0

Question

0 Figure 1: Triangle with three coordinates (xl, y1), (x2, y2), (x3, y3) Problem Statement Given coordinates of three point A, B, C of a triangle. Write a script to compute perimeter and area of triangle based on following formulas Distance between two points A and B daB - V(xB- r)2 + (yB -ya)2, where (xA,ya). (xB, yB) are coordinates of points A, B Area of a triangle ABC Input Data (xl, yl). (x2, y2). (x3, y3), are coordinates of three point A, B, C (cm) Output Data The three sides of the triangle: daB, dac, dBcperimeterABC, and areaABC in square centimeters Before You Begin 1. Start MATLAB and change your Current Folder to the location of your flash drive (e.g., K:/MATLAB programs/) If you forget to do this, your MATLAB programs will not be ac- cessible whenever the computers in this lab are cleared, which is throughout the semester 2. In the Command Window, type edit triangle yourLastName.m MATLAB should open the file if you have saved it in the correct location of the current folder Getting Started Include header comments formatted as show below, using your own name and ID number in the beginning of your script file:

Explanation / Answer

clc
prompt = 'Enter co-ordinate x1 : ';
x1 = input(prompt);
prompt = 'Enter co-ordinate y1 : ';
y1 = input(prompt);
prompt = 'Enter co-ordinate x2 : ';
x2 = input(prompt);
prompt = 'Enter co-ordinate y2 : ';
y2 = input(prompt);
prompt = 'Enter co-ordinate x3 : ';
x3 = input(prompt);
prompt = 'Enter co-ordinate y3 : ';
y3 = input(prompt);
dAB = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
dBC = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
dAC = sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
fprintf('Triangle ABC of sides %d cm , %d cm , %d cm . ',dAB,dBC,dAC);
p = (dAB+dAC+dBC);
fprintf('Perimeter = %d cm. ',p);
area = sqrt(p*(p-dAB)*(p-dAC)*(p-dBC));
fprintf('Area = %d cm . ',area);