Java-Gaming.org Hi !
 Featured games (88) games approved by the League of Dukes Games in Showcase (681) Games in Android Showcase (196) games submitted by our members Games in WIP (744) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Quick! Is there a Mathematician in the house?!  (Read 2756 times) 0 Members and 1 Guest are viewing this topic.
Dreamcatchermatt

Junior Devvie

 « Posted 2010-08-05 16:48:48 »

I've always wanted to say that...

This is slightly off topic, but still part of my Java project work, so I thought there might be someone here that can help me.

I'm working on a neural network project, and what i need to do is take the following sin wave (in black) and create the red line, which is the ideal output of the network.

Currently I've been doing this manually in Excel, because i have no idea how to calculate this. Basically, when the angle is at the 90 degree position, the output needs to be 1, and at the 270 degree position, it needs to be -1, and anywhere else it needs to be as close to zero as possible.

I probably wouldn't be the first to say I'm terrible with Trig'

Thanks all,
Matt

teletubo
Global Moderator

JGO Wizard

Medals: 70
Projects: 4
Exp: 8 years

 « Reply #1 - Posted 2010-08-05 16:54:57 »

cant you just write a function that does exactly what you described ?

 1  2  3  4  5  6  7  8  9  10  11  12 `/*** theta given in radians*/function myFunc(double theta){double sin = Math.sin(theta);if (sin==1 || sin==-1) return sin;return 0 ; }`

I have the felling I don't completely understand what you want, but anyway ...

Riven

« JGO Overlord »

Medals: 1220
Projects: 4
Exp: 16 years

 « Reply #2 - Posted 2010-08-05 16:58:42 »

Untested:
 1  2  3  4  5  6  7  8  9  10 `final float range = 15.0f;float degrees = ...; // anythingdegrees %= 360; // -359..359degrees += 360; // 1..719degrees %= 360; // 0..359if(isBetween(degrees,  90-range,  90+range))  return (range-Math.abs( 90-degrees)) / +range;if(isBetween(degrees, 270-range, 270+range))  return (range-Math.abs(270-degrees)) / -range;return 0.0f;`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Riven

« JGO Overlord »

Medals: 1220
Projects: 4
Exp: 16 years

 « Reply #3 - Posted 2010-08-05 17:01:32 »

Alternatively, if you don't need the linear ramp:
 1  2  3 `double highNumber = 500; // seems to give good resultsdouble oddNumber = highNumber | 1; // otherwise you might end up without negative valuesMath.pow(Math.sin(angle), oddNumber);`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Dreamcatchermatt

Junior Devvie

 « Reply #4 - Posted 2010-08-06 08:52:19 »

Alternatively, if you don't need the linear ramp:
 1  2  3 `double highNumber = 500; // seems to give good resultsdouble oddNumber = highNumber | 1; // otherwise you might end up without negative valuesMath.pow(Math.sin(angle), oddNumber);`

I think this is what I need.

I actually need to do this bit of code as an Excel formula rather than java code, to them save out as a CSV file and use with my program. I can sort that out though, its just the math that gets me

Thanks guys!

EDIT:
 1 `double oddNumber = highNumber | 1; // otherwise you might end up without negative values`

what does this line actually do? I've not come across inclusive OR before. (and I'm not getting any negative values)

EDITEDIT:

http://support.microsoft.com/kb/q132686/ Microsoft has no need for your primitive BODMAS! Blah!
Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #5 - Posted 2010-08-06 13:40:53 »

It will make sure the last bit is set.

ex.
101011011000 is OR'd with 0001 so it becomes 101011011001.

01101101 remains 01101101 because the last bit is already set.

See my work:
OTC Software
DzzD
 « Reply #6 - Posted 2010-08-06 16:33:41 »

Quote
what does this line actually do? I've not come across inclusive OR before. (and I'm not getting any negative values)

it return an odd number when input is even otherwise it return the same number

1 => 1
2 => 3
3 => 3
4 => 5
etc...

Dreamcatchermatt

Junior Devvie

 « Reply #7 - Posted 2010-08-06 18:24:06 »

Ahh, cool, that's actually a really useful thing to know
Cheers.

I did want to go down the Excel rout with this (for the graphing functions), but I may just write a program that dumps out the CSV's instead...

THis is getting further off topic, but has anyone found a really simple graphing package for java and swing? I cant remember which ones i've tried, but I've never found one that works, or is far too complicated and finiky to use for me to bother trying
teletubo
Global Moderator

JGO Wizard

Medals: 70
Projects: 4
Exp: 8 years

 « Reply #8 - Posted 2010-08-06 19:05:23 »

http://www.jfree.org/jfreechart/

I think this one is pretty straightforward, and it is very popular (i.e. there are a lot of faqs and tutorials).

Dreamcatchermatt

Junior Devvie

 « Reply #9 - Posted 2010-08-07 00:17:08 »

Hay, I got it working! Now I can get back to actual real programming

I feel really stupid asking this, but can anyone explain to me why raising to a power of an even number always returns a positive, and raising to the power of a odd number will do both positive and negative?

thanks for the graphing tip, I'm giving jFreeChart a go.
Riven

« JGO Overlord »

Medals: 1220
Projects: 4
Exp: 16 years

 « Reply #10 - Posted 2010-08-07 10:28:09 »

I feel really stupid asking this, but can anyone explain to me why raising to a power of an even number always returns a positive, and raising to the power of a odd number will do both positive and negative?

As you might remember from highschool:
+2*+2=+4
-2*+2=-4
+2*-2=-4
-2*-2=+4

In general:
[positive] * [positive] = [positive]
[positive] * [negative] = [negative]
[negative] * [negative] = [positive]

Let's write it out:
-2^1 =  -2    =  -2
-2^2 =  -2*-2 =  +4
-2^3 =  +4*-2 =  -8
-2^4 =  -8*-2 = +16
-2^5 = +16*-2 = -32
-2^6 = -32*-2 = +64

You can see that raising -2 to an odd number, the result is negative, and with an even number, the result is positive.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Hydroque (45 views) 2016-06-22 02:17:53 SwampChicken (46 views) 2016-06-20 13:22:57 SwampChicken (45 views) 2016-06-20 13:22:49 SwampChicken (38 views) 2016-06-20 13:22:26 Hydroque (81 views) 2016-06-15 08:22:50 Hydroque (72 views) 2016-06-13 06:40:55 DarkCart (192 views) 2016-05-29 02:30:33 Hydroque (161 views) 2016-05-26 14:45:46 Mac70 (168 views) 2016-05-24 21:16:33 theagentd (151 views) 2016-05-14 18:38:35
 theagentd 42x Spasi 41x NegativeZero 38x KaiHH 31x princec 27x LiquidNitrogen 23x ags1 19x h.pernpeintner 13x ra4king 12x CoDi^R 10x purenickery 10x kingroka123 10x Opiop 9x DarkCart 8x Hydroque 8x Archive 7x
 Making a Dynamic Plugin Systemby Hydroque2016-06-25 00:13:25Java Data structures2016-06-13 21:22:09Java Data structures2016-06-13 21:20:42FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org