## Trigometric Graph

Shape and space, angle and circle properties, ...
neonash7777
Posts: 75
Joined: Fri Aug 11, 2006 3:53 am
Location: ND
Contact:

### Trigometric Graph

Ok when you graph sine you get the S shaped thing. It's starts with an up hump. I need an equation for a parabola whose curve above the x axis matches up with the first hump of sine.

Essentially then there will be an equation that will do the sine function for you.
All you do is reduce the angle mod 180, enter that into the equation and solve for Y. Then if the original angle mod 360 is > 180 we tack on a minus sine.

Even if the equation is only aprx close so that it gets to like the 3rd decimal spot, that'ld be cool.

Thanks in advance!
Phi, it's a whole "h" of a lot cooler than pi!
zrosnbrick
Posts: 137
Joined: Fri Mar 17, 2006 3:58 am
Location: Madison, WI, USA
Using Taylor Series', I get the following approximation for sin(x) which holds true for about the first "hump" (0 to pi):

x - (1/6)x3 + (1/120)x5 - (1/5040)x7 + (1/362880)x9
[zeta]([alpha] + [beta]i) = 0 [imp] [alpha] = 1/2
[pi] + e
zrosnbrick
Posts: 137
Joined: Fri Mar 17, 2006 3:58 am
Location: Madison, WI, USA
However, you really only need an approximation which holds true for the first half of the first "hump" (0 to pi/2):

x - (1/6)x3 + (1/120)x5
[zeta]([alpha] + [beta]i) = 0 [imp] [alpha] = 1/2
[pi] + e
ThomasH
Posts: 117
Joined: Sun Mar 26, 2006 8:41 am
Location: Berlin, Germany
zrosnbrick, it seems to me, that, if the factor in front of x*x is sufficient small, we will need the whole "hump" from zero to pi. And with the approximation, we still dont have the solution.
For me, problems like this are very well suited for the search of a zero: we look for a root of the function zero(x) = sin(x) - a * x * x . First we make a small list of values of zero(x) and pick two values x1, x2 with zero(x1)>0 and zero(x2)<0 (the process, I am describing, is "bisection"). Next we evaluate zero at xm=(x1+x2)/2 and keep xm and one of x1 or x2 (lets call it x0) in that way, that zero(xm) and zero(x0) have different signs again. We continue the process and end up very soon at sufficient significant places.
If we want to do it with less iterations, we should do it with the "newton" formula.
zrosnbrick
Posts: 137
Joined: Fri Mar 17, 2006 3:58 am
Location: Madison, WI, USA
Actually, the first formula I gave is valid up to two to three decimal places for values of 0 to pi.
[zeta]([alpha] + [beta]i) = 0 [imp] [alpha] = 1/2
[pi] + e
neonash7777
Posts: 75
Joined: Fri Aug 11, 2006 3:53 am
Location: ND
Contact:
zrosnbrick wrote:However, you really only need an approximation which holds true for the first half of the first "hump" (0 to pi/2):

x - (1/6)x3 + (1/120)x5
So let's say I have an angle ÃƒÆ’Ã…Â¸,
I reduce it mod 180
if it's [ÃƒÆ’Ã…Â¸(mod180)]>90 then we do 90-[ÃƒÆ’Ã…Â¸(mod90)]
this will mirror the second half to make a complete hump.

Then we plug that number into the equation and get the digital answer.
Then if the original number mod 360 is >180 we tack on a - sign.

Is this correct?
~~~~~~
Here I wrote a code

Code: Select all

  dim x as single
dim z as single
x=val(editfield1.text)
z=x mod 180
if z>90 then
z=90-z
end if
z=z-(1/6)*(Pow(z,3))+(1/120)*(Pow(z,5))
If (x mod 360)>180 then
z=z*-1
end if
editfield2.text=str(z)

It doesn't work...what's wrong?

~~~~~
I guess you did say it worked from 0-pi/2 but even the the equation gets off quite a bit.... Isn't there some parabola that can match exactly?
Phi, it's a whole "h" of a lot cooler than pi!
harryh
Posts: 2091
Joined: Tue Aug 22, 2006 9:33 pm
Location: Thessaloniki, Greece
neonash7777 wrote:It doesn't work...what's wrong?
The expansion suggested by zrosnbrick, requires x to be in radians (not degrees). Judging by the statements "z=x mod 180", "if x>90 then..." etc which you use in your program, I assume you want to enter your angle in degrees. So, before your statement z=z-(1/6)*(Pow(z,3))+(1/120)*(Pow(z,5))
you have to add something like z=z*pi/180 to make it work.

Before that, when the angle (in degrees) is z>900 you should set z=180-z (rather than 90-z), because the 'hump' is symmetric about z=900 ( e.g. sin 1000=sin 800 ).

In addition, depending on the version of VB you are using, (1/6) and (1/120) may evaluate to integers, in which case they will always result to zero. If this happens, change them to (1./6) and (1./120) to force their evauation to floating-points.

Finally, I doubt that your approach will work for some negative values of the angle. I think that for e.g. x=-150, the function (x mod 180) returns -150, rather than 30, which is what you may have expected. I believe that you can find your way around this small difficulty. If not, say so and we'll help.
... Isn't there some parabola that can match exactly?
No, there is no such 'parabola'. The three-term expansion that zrosnbrick gave, will give a result accurate to 4 or 5 decimal digits for angles 00 to 450 and less accurate results for larger angles (you will only get results accurate to 2 or 3 decimal digits for angles approaching 900). If you need higher accuracy you can use the five-term expansion, and if that's still not good enough for your purposes, you can use even more terms. Just remember that, whereas (for a certain small range of angles) all these look a bit like parabolas, they are definitely not parabolas in the strict mathematical sense.
hk
Administrator
Posts: 11316
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands
Here are some functions to calculate sin and cos for any angle in degrees.
The error is always less then 6*10^-6.
The costants are specially calculated so that the special values 0,30,45,60 etc are calculated with a very great precision.
The functions mysmallcos and mysmallsin are auxiliary functions and it's better not to use them directly unless you are knowing what you do.

Code: Select all

function mysmallsin(x:single):single;
const
a=0.0174526678073878687;
b=-8.84917330915926673E-7;
c=1.28697001273234128E-11;
var y:single;
begin
//mysmallsin:=a*x+b*power(x,3)+c*power(x,5) can be written as:
y:=x*x;
mysmallsin:=x*(a+y*(b+c*y));
end;

function mysmallcos(x:single):single;
const
a=-0.000152307339409949027;
b=3.86373894910804713E-9;
c=-3.78865505963604336E-14;
begin
//mysmallcos:=1+a*power(x,2)+b*power(x,4)+c*power(x,6) can be written as:
x:=x*x;
mysmallcos:=1+x*(a+x*(b+c*x))
end;

function mycos(z:single):single;
var x,y:single;
begin
z:=abs(z);
while z>360 do z:=z-360;
if z>180 then z:=360-z;
if z>90 then x:=180-z else x:=z;
if x<65 then y:=mysmallcos(x) else y:=mysmallsin(90-x);
if z>90 then y:=-y;
mycos:=y;
end;

function mysin(z:single):single;
begin
mysin:=mycos(90-z);
end;

entitycs
Posts: 1
Joined: Wed Dec 15, 2010 4:29 am

### Re: Trigometric Graph

For f(x)=sin(x):

The curve starts with x and y equal to zero; y works its way to one, and then repeats, with a period of 2 Pi.

The top of the curve is when y = 1 (one). This happens when x is equal to Pi/2, or half Pi.

Using the vertex formula, g(x) = a(x-h)^2 + k, we can insert the maximum of f(x) as the vertex, (Pi/2 , 1).

then solve for a. So g(x) = a(x-h)^2 + k becomesg(x) = a[x- (Pi/2) ]^2 + 1.

You can then plug in other (x , y) coordinates of the formula f(x) into the formula g(x); (Pi/6 , 1/2); (Pi , 0); (Pi/4 , sqrt(2)/2);

You end up with formulas of REAL parabolas, ranging from g(x)=(-4/Pi)[x - (Pi/2)]^2 + 1 to g(x)=(-4.5/Pi)[x - (Pi/2)]^2 + 1.

You could make a "piecewise" function in which the -4 to -4.5 is not a constant, but a variable tied to x...

-4.5 would make the values near the x-intercepts more accurate. -4.25 splits the difference pretty well.

So the most accurate real parabola, IMO, would be g(x)=(-4.25/Pi)[x - (Pi/2)]^2 + 1.

variable a = -4.25;
variable h = (Pi/2);
variable k = 1;

Once your x (or i in loop) is equal to 2*Pi, you multiply variables a and k by negative one. h is increased or decreased by 2*Pi depending on x.
So once you have reached ~2*Pi, OR g(x) is not greater than 0 OR if x % 2*Pi ==0 OR whatever... THEN

variable a *= -1;
variable h += (2*Pi);
variable k *= -1;

You can run the same function twice, then loop for a period. hypothetically, of coarse.
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 10:43 am
Location: Netherlands

### Re: Trigometric Graph

Any parabola will be significantly off, since the power series of the sine at $\pi/2$ is equal to that of the cosine at zero, which is (first terms) given by $$\sin(x+\pi/2)=\cos(x)\approx 1-\frac{x^2}{2}+\frac{x^4}{4!}+...$$ from which we see that the quartic term contributes a factor 1/24 and the quadratic term contributes 1/2. So if your formula is to be correct up to 0 and $\pi$, there is no parabola which is everywhere correct up to the third digit.

For your interest, the formal power series of sine at $\pi/2$ is given by $$sin(x+\pi/2)=\sum_{n=0}^\infty \frac{(-1)^nx^{2n}}{(2n)!}$$ 