Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Use the first form of Heron's formula to give a function areah, which gives the area of a triangle. Test your answer on the isosceles triangle {{-1 ,0}, {1, 0}, {0, 1}, {-1, 0}}.

This is what I have:

areah[triangle_] := 
 (lenbroke[triangle]/2 Product[lenbroke[triangle]/2 - 
   len (lineseg (triangle[[i]])), {i, 1, 3}])

This is what I get when I test it:

areah[{{-1, 0}, {1, 0}, {0, 1}, {-1, 0}}]

I don't know what is wrong because when I test it, it doesn't work.

share|improve this question
    
Hi, there seems to be a lot missing from your post: lenbroke, len, lineseg. And a triangle has three vertices, not four. Please correct these problems. –  Michael E2 Oct 13 '13 at 0:32
    
@MichaelE2 Those are three vertices, but the triangle is stammering –  belisarius Oct 13 '13 at 0:58
    
4 because it has to go back to where it originally was. –  Sam Oct 13 '13 at 1:28
    
Oops, poor eyesight - sorry. I still don't see the definitions of the other variables/functions. Perhaps you're filling them in now. –  Michael E2 Oct 13 '13 at 1:36
1  
I used a = {-1, 0}; b = {1, 0}; c = {0, 1}; s = 1/2 Abs[Det[{a - b, a - c}]] –  minthao_2011 Oct 13 '13 at 3:04
show 2 more comments

closed as off-topic by m_goldberg, Sjoerd C. de Vries, Artes, Yves Klett, Michael E2 Oct 13 '13 at 17:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – m_goldberg, Sjoerd C. de Vries, Artes, Yves Klett, Michael E2
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Maybe this is what you want:

areah[triangle_] := 
 Module[{a, b, c, s}, 
  {a, b, c} = Norm /@ Differences[triangle]; 
  s = (a + b + c)/2; Sqrt[s (s - a) (s - b) (s - c)]]

areah[{{-1, 0}, {1, 0}, {0, 1}, {-1, 0}}] // Simplify

1

But I prefer the solution of @minthao_2011 using determinant.

share|improve this answer
add comment

I used

a = {-1, 0}; b = {1, 0}; c = {0, 1}; s = 1/2 Abs[Det[{a - b, a - c}]] 

1

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.