|
|
| David Frank 2006-10-19, 4:14 am |
| Anyone have source for a function y = triangular(x)
that can substitute for y = sin(x) but returns a triangular wave
instead?
| |
| Brooks Moses 2006-10-19, 4:14 am |
| David Frank wrote:
> Anyone have source for a function y = triangular(x)
> that can substitute for y = sin(x) but returns a triangular wave
> instead?
y = abs(modulo(x, 2.0) - 1.0)
Or something like that, suitably scaled and shifted around.
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
| |
| Lane Straatman 2006-10-19, 4:14 am |
|
"David Frank" <dave_frank@hotmail.com> wrote in message
news:45370d7f$0$17443$ec3e2dad@news.usenetmonster.com...
> Anyone have source for a function y = triangular(x)
> that can substitute for y = sin(x) but returns a triangular wave
> instead?
I think that this could be topical here.
What I can't discern from the original post is whether OP is looking for
things defined by their proximity to the diagonal--necessarily
symmetrical--or s s geometry. EC
| |
| Tobias 2006-10-19, 4:14 am |
| David Frank wrote:
> Anyone have source for a function y = triangular(x)
> that can substitute for y = sin(x) but returns a triangular wave
> instead?
Like this?
function triag(x)
double precision :: x, triag
double precision, parameter :: M_PI =
3.1415926535897932384626433832795029d0
triag = (abs(mod(abs(x-M_PI/2.0),2.0*M_PI)-M_PI)/M_PI*2.0d0)-1d0
end function triag
Tobias
| |
| David Frank 2006-10-19, 4:14 am |
|
"Tobias" <burnus@net-b.de> wrote in message
news:1161239925.559810.88100@f16g2000cwb.googlegroups.com...
> David Frank wrote:
>
> Like this?
>
> function triag(x)
> double precision :: x, triag
> double precision, parameter :: M_PI =
> 3.1415926535897932384626433832795029d0
> triag = (abs(mod(abs(x-M_PI/2.0),2.0*M_PI)-M_PI)/M_PI*2.0d0)-1d0
> end function triag
>
Thanks, your function works fine.
I was struggling trying to make Brooks's statement work for x = radians and
was getting a sawtooth instead of a triangular wave.
..
> Tobias
>
| |
|
| "David Frank" <dave_frank@hotmail.com> wrote in message
news:45373208$0$17427$ec3e2dad@news.usenetmonster.com...
>
> "Tobias" <burnus@net-b.de> wrote in message
> news:1161239925.559810.88100@f16g2000cwb.googlegroups.com...
>
> Thanks, your function works fine.
> I was struggling trying to make Brooks's statement work for x = radians and
> was getting a sawtooth instead of a triangular wave.
A sawtooth _is_ triangular wave.
| |
| glen herrmannsfeldt 2006-10-30, 7:15 pm |
| robin wrote:
(snip)
> A sawtooth _is_ triangular wave.
More usual, a triangle wave has equal rise and fall times,
where sawtooth has a slow rise and fast fall, or fast
rise and slow fall.
-- glen
| |
|
| "glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:Lp-dneiF1Jl8vaLYnZ2dnUVZ_vqdnZ2d@comcast.com...
[color=darkred]
[color=darkred]
>
> More usual, a triangle wave has equal rise and fall times,
It can have any shape, as long as it's in the shape of a triangle.
> where sawtooth has a slow rise and fast fall, or fast
> rise and slow fall.
|
|
|
|