Hi,
If I follow you correctly, you could write a function:
foo <- function(a,b,gamma){
c <- sqrt(a^2 + b^2 -2*a*b*cos(gamma))
s <- (a+b+c)/2
A <- sqrt(s*(s-a)*(s-b)*(s-c))
return(A)
}
I hope I didn't make mistakes, but it can still help you, I guess.
Ivan
Le 2/25/2011 10:11, zbynek.jano...@gmail.com a écrit :
I am having following problem:
I´m constructing model for calculation of area of triangle.
I know sides a, b, and gamma angle.
I wish to calculate the area using heron´s formula:
S<- sqrt(s*(s-a)*(s-b)*(s-c))
where
s<- (a+b+c)/2
and c is calculated using law of cosines:
c<- sqrt(a^2 + b^2 -2*a*b*cos(gamma))
since i am calculating a regression model, i need derivation of this
expression for area S.
something like (D(expression.S,c("a","b")))
To write it all into a single expression, it is too complicated, so i would
like to use some kind of substitution. however, if i try:
s.e<- substitute(expression((a+b+c)/2), list(c =
expression(sqrt(a^2+b^2-2*a*b*cos(gamma))))),
I get
s.e
expression((a + b + expression(sqrt(a^2 + b^2 - 2 * a * b * cos(gamma))))/2)
which is not what I wanted
Can someone point me to the right direction?
--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de
**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.