Displaying 2 results from an estimated 2 matches for "2sin".
Did you mean:
2min
2011 Aug 05
1
Translate Sine Function in R?
...fit my observations using
the general formula:
y=a*sin(b[x+h*pi)]+k
where a = amplitude, b=period, h=phase shift, and k=vertical shift
I want to use following translation to bring the sine function up onto the
y-axis to range from 0-1, and this will place the wave on the x-axis from
0-pi/2.
y=1/2sin(2[x+ 1/4*pi]) + 1/2
Additionally, I need to spread this along a x-axis that spans 1-153 (days).
Can anyone help with this? I seem to be able to use the curve function fine,
but entering the translations doesn't seem to provide an answer.
Here is an example of the data set I am trying to '...
2002 Aug 06
1
Questions about lexical scope
...], n)
}
rule(g, a[1], b[1])
}
I modified the function name from "integrate" to "bv.integrate".
To integrate f(x,y)=sin(x + y) over the unit square,
it works:
> bv.integrate(function(x, y) sin(x + y), c(0,0), c(1,1))
[1] 0.773651
(compare with .7736445 calculated from 2sin(1)*(1 - cos(1)))
Then I write a function using trapezoidal rule as follows:
trapezoidal <- function(f, a, b, n=100) {
h <- (b - a)/n
i <- 1:n
sum(f(a + (i - 1)*h), f(a + i*h))*h/2
}
I checked with
> trapezoidal(sin, 0, 1)
[1] 0.4596939
> 1 - cos(1)
[1] 0.4596977
and
&...