looking for a formulae that would get me the desired curve

Fredeke

New member
Joined
Nov 20, 2019
Messages
5
Hi everyone !
Posting here for the first time.

I am a part-time independent code developer, and in some aspect of my present project, I might have bitten more math than I can chew. I took advanced math as a teenager, but that was decades ago.

Here's the thing: I'm trying to produce a cyclic function that would be like a sine, except with steeper slopes around Y=0 and then more flattened at the peaks. And symmetrical the way a sine is.

I'm coding in a rudimentary language, and the arithmetic tools at my disposal, besides +-*/, are:
sine, cosine, tangent, arcsine, arccosine, arctangent, modulo, x^y (where both x and y are real), e^x, log (x), and absolute value.

Is there a way to the desired result using these operations?
 
Last edited:
Ah, experimenting further, I may have found something...

It would seem that any root of a sine would produce that kind of curve. However, I don't understand why the curve is discontinuous. I mean 0 to pi gives a positive curve of the shape I am aiming for, but then values from pi to 2pi give no result, and then that pattern is repeated to infinity.

I sure can get around that by placing conditions in the code, and shifting and inverting results. That would solve it for me. But is there a more elegant - a more 'mathematical' - way of getting a continuous symmetrical curve ?

I am using fooplot as my scratchpad, btw.
Oh, and also: I don't care about values of x < 0
 
Last edited:
The domain of the any even root function is the non-negative reals, and even odd root functions produce multiple results on the negative reals.

The sine goes negative on \(\displaystyle \left(\pi, 2\pi\right)\)

What you want is \(\displaystyle \sqrt{|\sin(x)|} sgn(\pi - x)\)

or to adjust for the shape you want

\(\displaystyle \left|\sin(x)\right|^\alpha sgn(\pi - x),~0 < \alpha < 1\)

\(\displaystyle sgn(x) = \begin{cases}-1 &x < 0\\1 &0 \leq x \end{cases}\)
 
Last edited:
The domain of the any even root function is the non-negative reals, and even odd root functions produce multiple results on the negative reals.

The sine goes negative on \(\displaystyle \left(\pi, 2\pi\right)\)

What you want is \(\displaystyle \sqrt{|\sin(x)|} sgn(\pi - x)\)

or to adjust for the shape you want

\(\displaystyle \left|\sin(x)\right|^\alpha sgn(\pi - x),~0 < \alpha < 1\)

\(\displaystyle sgn(x) = \begin{cases}-1 &x < 0\\1 &0 \leq x \end{cases}\)
Why not sgn(sin(x))? Not sure what domain OP needs.
 
Why not sgn(sin(x))? Not sure what domain OP needs.

read the original post. OP is trying to flatten out a sine wave to obtain some level of smoothed square wave.

There are other ways to accomplish this but this is what OP is doing.
 
read the original post. OP is trying to flatten out a sine wave to obtain some level of smoothed square wave.

There are other ways to accomplish this but this is what OP is doing.

The sgn part of \(\displaystyle \sqrt{|\sin(x)|} sgn(\pi - x)\) works for certain values of x, which may or may not be the domain OP needs. I am asking whether replacing it with sgn(sin(x)) would make sense. It would provide correct sign for larger domain.
 
The sgn part of \(\displaystyle \sqrt{|\sin(x)|} sgn(\pi - x)\) works for certain values of x, which may or may not be the domain OP needs. I am asking whether replacing it with sgn(sin(x)) would make sense. It would provide correct sign for larger domain.

ahh gotcha and you are entirely correct.
 
Thanks! Yeah I forgot about the multiple results. That's what got me confused.

The domain I need is positive values of x. (If I understand the concept of domain correctly)

sgn(x) will be implemented through if statements. As for which of these variants to favor, code optimization should prevail.

It's late now here in Belgium. I'll get back at it tomorrow with a fresh brain. Thanks again, everyone.
 
read the original post. OP is trying to flatten out a sine wave to obtain some level of smoothed square wave.

There are other ways to accomplish this but this is what OP is doing.
I'm curious about the other ways to obtain a smoothed square wave.
(Again, I'm only interested in x>=0, if that makes a difference)
 
Take the Taylor series of the square wave an only include the first k terms, k being adjusted to your taste.

One downside of this method is that it will have ripple.
 
I'm not familiar with Taylor, but is it the idea that any complex periodic phenomenon is the sum of a finite or infinite number of sine-shaped phenomenons?

I considered it, but discarded the solution for the reason you say: rippled peaks, and also because it would probably increase computation, and my code needs to run in real time, taking as little cpu power as possible (because there will be much more to do simultaneously).

Thanks for the discussion anyway :)
 
Top