etingwall Posted January 24, 2009 Share Posted January 24, 2009 Hi, Let's say I've got a table of air properties in a MySQL database. For simplicity let's say it looks like: Temperature | Density 100 | 1.03 150 | 0.99 200 | 0.94 300 | 0.87 400 | 0.82 Notice that the temperature data is not necessarily in equal increments. I grab the data and create arrays with it. Now I have a surface temperature $TSurface that will be in between these values....say $TSurface = 212 I want to interpolate the density data so that I can get the density at 212 degrees. How would I grab the two temperatures above and below 212 and then the corresponding densities? Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/ Share on other sites More sharing options...
corbin Posted January 24, 2009 Share Posted January 24, 2009 You will need to find some kind of regression calculator. It's obviously not linear regression, but besides that, I have no idea. Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-744930 Share on other sites More sharing options...
etingwall Posted January 24, 2009 Author Share Posted January 24, 2009 Thanks for the response...it's moving me in the right direction. Maybe I included too much detail with the original question. The math involved is simple. For a novice like me, the hard part is figuring how to pull specific numbers out of the array. If I have a value of 212, how can I grab 200 and 250 out of the array, along with the corresponding densities? Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745310 Share on other sites More sharing options...
.josh Posted January 24, 2009 Share Posted January 24, 2009 depends on what your array format is. Are you using a multi-dim array like this? $data[0] = array('temp' => 100, 'dens' => 1.03); $data[1] = array('temp' => 150, 'dens' => 0.99); etc... or are you doing a single key=>val temp=>dens array like this? $data = array(100 => 1.03, 150 => 0.99, etc...); Or are you doing some other array format? Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745339 Share on other sites More sharing options...
Daniel0 Posted January 24, 2009 Share Posted January 24, 2009 You will need to find some kind of regression calculator. It's obviously not linear regression, but besides that, I have no idea. It's a fourth degree polynomial... [tex]f(x) = -8 \cdot 10^{-11} \cdot x^4 + 8 \cdot 10^8 \cdot x^3 - .000027x^2 + .0028x + .948[/tex] Approximately... Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745343 Share on other sites More sharing options...
.josh Posted January 24, 2009 Share Posted January 24, 2009 f(x) = -8*10-11 * x4 + 8*108 * x3 - .000027*x2 + .0028x + .948 Hey I'm not sure if you knew or not, but we have a nifty latex button for this sort of thing. Yep. Some admin recently installed it because he thought it would be useful. Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745349 Share on other sites More sharing options...
Daniel0 Posted January 24, 2009 Share Posted January 24, 2009 f(x) = -8*10-11 * x4 + 8*108 * x3 - .000027*x2 + .0028x + .948 Hey I'm not sure if you knew or not, but we have a nifty latex button for this sort of thing. Yep. Some admin recently installed it because he thought it would be useful. Thought of that after I posted and edited it shortly after Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745351 Share on other sites More sharing options...
etingwall Posted January 24, 2009 Author Share Posted January 24, 2009 Thanks for the input. This is what I ended up with. Using the high and low keys and high and low temperatures allows me to interpolate several different arrays for Diffusivity, Conductivity, etc. $TInteriorAverage = ($TInteriorSurface + $TColdSpace)/2; foreach($TemperatureArray as $key=>$value){ if($value-$TInteriorAverage>=0){ $TInteriorHigh=$value; $InteriorHighKey=$key; $TInteriorLow=$LastValue; $InteriorLowKey=$LastKey; break; } else{ $LastValue=$value; $LastKey=$key; } } Quote Link to comment https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/#findComment-745587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.