For Programmers: Free Programming Magazines  


Home > Archive > Fortran > October 2006 > triangular wave









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author triangular wave
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 ss 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
>



robin

2006-10-30, 7:15 pm

"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

robin

2006-10-30, 7:15 pm

"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.





Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com