My Math Forum Help reversing an algorithm...

 Applied Math Applied Math Forum

 January 9th, 2014, 11:53 AM #1 Newbie   Joined: Jan 2014 Posts: 3 Thanks: 0 Help reversing an algorithm... I've found an algorithm that converts salinity in water to density depending on temperature and pressure. I need to be able to do the opposite aswell and I'm far from a math genius. I might even be using the wrong part of the forum and if so please move this thread . Below is the algorith and it's copied from C# code. Math.Sqrt for example means square root Please help, im deperate! var Temperature = 25; var Salinity = 40; var Pressure = 0; var rho_w = 999.842594 + Temperature * (6.793952e-2 + Temperature * (-9.095290e-3 + Temperature * (1.001685e-4 + Temperature * (-1.120083e-6 + Temperature * 6.536332e-9)))); var Kw = 19652.21 + Temperature * (148.4206 + Temperature * (-2.327105 + Temperature * (1.360477e-2 - Temperature * 5.155288e-5))); var Aw = 3.239908 + Temperature * (1.43713e-3 + Temperature * (1.16092e-4 - Temperature * 5.77905e-7)); var Bw = 8.50935e-5 + Temperature * (-6.12293e-6 + Temperature * 5.2787e-; var p1 = 0.1 * Pressure; var S12 = Math.Sqrt(Salinity); var ro = rho_w + Salinity * (8.24493e-1 + Temperature * (-4.0899e-3 + Temperature * (7.6438e-5 + Temperature * (-8.2467e-7 + Temperature * 5.3875e-9))) + S12 * (-5.72466e-3 + Temperature * (1.0227e-4 - Temperature * 1.6546e-6) + S12 * 4.8314e-4)); var xkst = Kw + Salinity * (54.6746 + Temperature * (-0.603459 + Temperature * (1.09987e-2 - Temperature * 6.1670e-5)) + S12 * (7.944e-2 + Temperature * (1.6483e-2 + Temperature * (-5.3009e-4)))) + p1 * (Aw + Salinity * (2.2838e-3 + Temperature * (-1.0981e-5 + Temperature * (-1.6078e-6)) + S12 * (1.91075e-4)) + p1 * (Bw + Salinity * (-9.9348e-7 + Temperature * (2.0816e-8 + Temperature * (9.1697e-10))))); var result = (ro / (1.0 - p1 / xkst));
 January 9th, 2014, 01:09 PM #2 Math Team   Joined: Sep 2007 Posts: 2,409 Thanks: 6 Re: Help reversing an algorithm... "Reverse" it to determine what? Your algorithm, which has a number of "preliminary" computations, eventually finds a value for "result" so I presume your "reverse algorithm" would start with that, but to determine what value? "Temperature"?
 January 9th, 2014, 01:16 PM #3 Newbie   Joined: Jan 2014 Posts: 3 Thanks: 0 Re: Help reversing an algorithm... Im sorry i should have specified that. The algorithm takes in salinity and gives density and i want an algorithm that takes in density and gives salinity. The temperature and pressure can be static if that makes things easier. I dont need to change those
 January 11th, 2014, 10:09 AM #4 Newbie   Joined: Jan 2014 Posts: 3 Thanks: 0 Re: Help reversing an algorithm... Ok I've simplied this ALOT not . Maybe someone could crack it now? 997.047957507813 + salinity * (0.7592382734375 + Math.Sqrt(salinity) * (-0.004202035 + Math.Sqrt(salinity) * 4.8314e-4)) = density Please help me reverse this so I have a formula that converts density to salinity
 January 12th, 2014, 08:47 AM #5 Global Moderator     Joined: Nov 2006 From: UTC -5 Posts: 16,046 Thanks: 938 Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms Re: Help reversing an algorithm... You have a quartic equation in x = sqrt(salinity). It's of the form a + x^2 (b + x * (c + d*x)) = r and there's even a closed-form solution, if you like. But the quartic formula is even messier than the cubic formula, and neither is as nice as the quadratic formula. You can see it here http://www.wolframalpha.com/input/?i=a+ ... (c+%2B+d*x))+%3D+r but as you see it's pretty long (and has several cases). Alternately, you could use general root finding (or better, a polynomial method like Schonhage's method).

 Tags algorithm, reversing

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post oneup Elementary Math 4 September 2nd, 2013 04:08 AM Liqwde Computer Science 2 August 31st, 2010 08:59 PM OSearcy4 Calculus 4 October 17th, 2009 03:32 PM Gotovina7 Calculus 1 February 29th, 2008 09:30 AM Cat Number Theory 6 January 7th, 2007 07:32 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top