Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/142199-mathematical-interpolation/
Share on other sites

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?

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?

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...

 

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. 

 

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 :P

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;
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.