wonder Expert Licensed User Longtime User May 15, 2015 #1 So, I'm working on a little science project: B4X: Expand Collapse Copy Dim G = 6.67 * Power(10, -11) as Float Dim Earth_Mass = 5.97 * Power(10, 24) as Float 'in kilograms Dim Sun_Mass = 1.99 * Power(10, 30) as Float 'in kilograms Dim Distance = 1.5 * power(10, 11) as Float 'in meters B4X: Expand Collapse Copy Dim Gravitational_Force = (G * Sun_Mass * Earth_Mass) / Power(Distance, 2) as Float Log(Gravitational_Force) Output: Infinity I'm getting "Infinity" instead of the actual value. How can I handle such big numbers? Any suggestions? I'm not a math wizzard...
So, I'm working on a little science project: B4X: Expand Collapse Copy Dim G = 6.67 * Power(10, -11) as Float Dim Earth_Mass = 5.97 * Power(10, 24) as Float 'in kilograms Dim Sun_Mass = 1.99 * Power(10, 30) as Float 'in kilograms Dim Distance = 1.5 * power(10, 11) as Float 'in meters B4X: Expand Collapse Copy Dim Gravitational_Force = (G * Sun_Mass * Earth_Mass) / Power(Distance, 2) as Float Log(Gravitational_Force) Output: Infinity I'm getting "Infinity" instead of the actual value. How can I handle such big numbers? Any suggestions? I'm not a math wizzard...
thedesolatesoul Expert Licensed User Longtime User May 15, 2015 #2 If you change the order to: B4X: Expand Collapse Copy Log((G*Sun_Mass/Power(Distance,2))*Earth_Mass) it outputs 3.521849211074262E22 Not sure if that is the correct value. Alternatively you need the BigNumbers library. Upvote 0
If you change the order to: B4X: Expand Collapse Copy Log((G*Sun_Mass/Power(Distance,2))*Earth_Mass) it outputs 3.521849211074262E22 Not sure if that is the correct value. Alternatively you need the BigNumbers library.
thedesolatesoul Expert Licensed User Longtime User May 15, 2015 #3 Or use double instead of floats. Double uses 64 bit. http://en.wikibooks.org/wiki/Java_Programming/Primitive_Types Upvote 0
Or use double instead of floats. Double uses 64 bit. http://en.wikibooks.org/wiki/Java_Programming/Primitive_Types
wonder Expert Licensed User Longtime User May 15, 2015 #4 thedesolatesoul said: Or use double instead of floats. Double uses 64 bit. http://en.wikibooks.org/wiki/Java_Programming/Primitive_Types Click to expand... It worked!! Thank you so much!! It's the second time you save my code this week!! Thanks man!!! Upvote 0
thedesolatesoul said: Or use double instead of floats. Double uses 64 bit. http://en.wikibooks.org/wiki/Java_Programming/Primitive_Types Click to expand... It worked!! Thank you so much!! It's the second time you save my code this week!! Thanks man!!!
thedesolatesoul Expert Licensed User Longtime User May 16, 2015 #5 wonder said: It worked!! Thank you so much!! It's the second time you save my code this week!! Thanks man!!! Click to expand... Because you ask interesting questions in a way I can try them Upvote 0
wonder said: It worked!! Thank you so much!! It's the second time you save my code this week!! Thanks man!!! Click to expand... Because you ask interesting questions in a way I can try them
wonder Expert Licensed User Longtime User May 16, 2015 #6 I woke-up yesterday with the urge to build a miniature solar system. I'm trying to get stable orbits while inputing real data. So far all I managed to do, was to crash a few planets into the Sun. Files: Photoshop concept art: Upvote 0
I woke-up yesterday with the urge to build a miniature solar system. I'm trying to get stable orbits while inputing real data. So far all I managed to do, was to crash a few planets into the Sun. Files: Photoshop concept art:
thedesolatesoul Expert Licensed User Longtime User May 16, 2015 #7 If you are applying a singular force to the planet that is where it will go? I'm not sure what other forces play a factor to keep it in orbit. Upvote 0
If you are applying a singular force to the planet that is where it will go? I'm not sure what other forces play a factor to keep it in orbit.
wonder Expert Licensed User Longtime User May 16, 2015 #8 Well, I haven't got it to work properly yet, but last night I was temporarily able to get some stable orbits. I have only two velocity vectors. Vector A is the planet's linear speed (30 km/sec). Vector B is perpendicular to vector A and it's accelerated towards the Sun. B4X: Expand Collapse Copy Sub Acceleration_Towards_The_Sun(planet_index As Int) As Double Return (G * SpaceBody(Sun).Mass) / Power(Distance_Between_Two_SpaceBodies_in_Meters(planet_index, Sun), 2) End Sub Once I have it all figured out, I'll share the code. Upvote 0
Well, I haven't got it to work properly yet, but last night I was temporarily able to get some stable orbits. I have only two velocity vectors. Vector A is the planet's linear speed (30 km/sec). Vector B is perpendicular to vector A and it's accelerated towards the Sun. B4X: Expand Collapse Copy Sub Acceleration_Towards_The_Sun(planet_index As Int) As Double Return (G * SpaceBody(Sun).Mass) / Power(Distance_Between_Two_SpaceBodies_in_Meters(planet_index, Sun), 2) End Sub Once I have it all figured out, I'll share the code.
thedesolatesoul Expert Licensed User Longtime User May 16, 2015 #9 I need to take out my old books but I believe vector B needs to be a combination of the centripetal and centrifugal forces that would keep 'r' constant. Let me know whenever you make more interesting progress! Upvote 0
I need to take out my old books but I believe vector B needs to be a combination of the centripetal and centrifugal forces that would keep 'r' constant. Let me know whenever you make more interesting progress!