hw12_problem3

# hw12_problem3 - heron_A = sqrt(s(s side_a(s side_b(s side-c...

This preview shows pages 1–2. Sign up to view the full content.

function [heron_area] = TriArea(side_a,side_b,side_c)  % This function calculates the area of a triangle given the lengths of the   % three sides using Heron's equation.  % INPUT ARGUMENTS:   side_a = the length of side a of the triangle  %                    side_b = the length of side b of the triangle  %                    side_c = the length of side c of the triangle  % OUTPUT ARGUMENTS:  heron_area = the area of the triangle  % ---- Calculation Section ----     fprintf('One of the sides is negative or zero')               elseif      s = (side_a+side_b+side_c)/2;  % the half perimeter of the triangle

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: heron_A = sqrt(s*(s side_a)*(s side_b)*(s side-c)); end % Line #: 11 % Error: the logic incorrectly uses & conditions % Fix: change to side_a || side_b || side_c. % Line #: 13 % Error: uses elseif condition rather than else condition % Fix: change to else. % Line #: 15 % Error: the variable heron_A not returned by the function % Fix: change the variable to heron_area. % Line #: 15 % Error: undefined variable side-c % Fix: change the variable to side_c. % Line #: 11/12 % Error: if a side has negative length, heron_area not defined so function has undefined output. % Fix: add an initialization for heron_area to line 9....
View Full Document

## This note was uploaded on 05/02/2011 for the course ENGR 132 taught by Professor Kutson during the Spring '11 term at Purdue.

### Page1 / 2

hw12_problem3 - heron_A = sqrt(s(s side_a(s side_b(s side-c...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online