Solving Fourier's Law w/ Splines & Derivatives

  • Thread starter Thread starter BOAS
  • Start date Start date
  • Tags Tags
    Heating Law
AI Thread Summary
The discussion revolves around determining the thermal conductivity of a material using temperature data at specific points and applying the heat conduction equation. The user seeks guidance on calculating the derivative of the temperature function to evaluate thermal conductivity. Various methods for obtaining the temperature function and its derivative are suggested, including using spline interpolation with Python's SciPy library, Excel for quick trendline analysis, and numerical methods like Newton's Method or Finite Differences for derivative calculation. The importance of evaluating the derivative at the specified point (x = 0) is emphasized, with suggestions for both numerical and symbolic approaches. The user expresses appreciation for the advice and confirms familiarity with finite difference methods, indicating a preference for using central difference formulas for accuracy.
BOAS
Messages
546
Reaction score
19
Hello,

I am trying to determine the thermal conductivity of a material based on the following information.

##Q_x = - k \frac{dT}{dx}##

Temperature as a function of ##x, T(x)##;

##T(0) = 15##
##T(0.1) = 10##
##T(0.2) = 5##
##T(0.3) = 3##

and finally that ##Q_{x=0} = 40 \mathrm{Wm^{-2}}##

The way I am approaching this problem is to use a spline to interpolate the data, and then find the derivatives of this function. My problem is that I can't figure out how to evaluate the derivative at a given point.

For example, how do I evaluate the derivative at x = 0?

Python:
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import splev, splrep

x = np.array([0, 0.1, 0.2, 0.3],dtype=float)
T = np.array([15, 10, 5, 3],dtype=float)

xnew = np.linspace(0,0.3,100)
f = splrep(x,T,s=0)

ynew = splev(xnew,f,der=0)

yder = splev(xnew,f,der=1)

plt.grid(True)
plt.plot(x,T,'x',xnew,ynew,xnew,yder)
plt.show()
plt.close()
 
Last edited:
Technology news on Phys.org
To make sure we are on the same page,

You want to find the thermal conductivity, k, based the one-dimensional model for isotrpoic heat flux. You are given data points which were presumably taken from evenly spaces points on the surface of the object. This can obviously be used to construct a function relating the position to temperature-to an acceptable range.

Obtaining the Temperature Function:
Quick Way:
Plot the data in excel and add a trendline. One advantage of using Excel is being able to dynamically see how the residual changes with each model.
Take the derivative of the interpolated function by hand.

Python:
Use http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html. The first example on that page should be exactly what you are looking for.

Obtaining the Derivative
Quick Way:
Do it by hand.

Python:
Numerical Methods
Instead of explicitly taking the derivative of the equation obtained by interpolation, consider using Newton's Method or Finite Differences. scipy.optimize.Newton might be worth checking out.
Symbolic:
Instead of using a numerical method you can find libraries like SymPy that allow you to do symbolic algebra. This would obvoiusly be more accurate than a numerical method but would require you learn to interface with SymPY

Putting it Together
Now that the derivative is computed, it can be substituted into the equation for 1-d heat flux. Because you know what the value of Q is at the initial point, 0, evaluate the derivative at that point.
BOAS said:
For example, how do I evaluate the derivative at x = 0?
It depends on which method you chose to obtain the derivative.
If you are choosing to do a numerical method you will be including the point of interest in the algorithm.
Code:
double NewtonsMethod(double x)
{
double derivative;
//algorithm here
return derivative
}

int main()
{
cout<<"The derivative at 0 is :"<<NewtonsMethod(0);
return 0;
}

If you did it symbolically, you can probably just call the function like a function. It would look something like.
Code:
int main()
{
vector<int> x,y;
// fill x&y
derivative=Interpolation(x,y);
cout<<"The derivative at 0 is :"<<derivative(0);
return 0;
}

Once you have the numerical value for the derivative you can solve for the thermal conductivity.
 
Thomas Thelen said:
To make sure we are on the same page,

You want to find the thermal conductivity, k, based the one-dimensional model for isotrpoic heat flux. You are given data points which were presumably taken from evenly spaces points on the surface of the object. This can obviously be used to construct a function relating the position to temperature-to an acceptable range.

Obtaining the Temperature Function:
Quick Way:
Plot the data in excel and add a trendline. One advantage of using Excel is being able to dynamically see how the residual changes with each model.
Take the derivative of the interpolated function by hand.

Python:
Use http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html. The first example on that page should be exactly what you are looking for.

Obtaining the Derivative
Quick Way:
Do it by hand.

Python:
Numerical Methods
Instead of explicitly taking the derivative of the equation obtained by interpolation, consider using Newton's Method or Finite Differences. scipy.optimize.Newton might be worth checking out.
Symbolic:
Instead of using a numerical method you can find libraries like SymPy that allow you to do symbolic algebra. This would obvoiusly be more accurate than a numerical method but would require you learn to interface with SymPY

Putting it Together
Now that the derivative is computed, it can be substituted into the equation for 1-d heat flux. Because you know what the value of Q is at the initial point, 0, evaluate the derivative at that point.

It depends on which method you chose to obtain the derivative.
If you are choosing to do a numerical method you will be including the point of interest in the algorithm.
Code:
double NewtonsMethod(double x)
{
double derivative;
//algorithm here
return derivative
}

int main()
{
cout<<"The derivative at 0 is :"<<NewtonsMethod(0);
return 0;
}

If you did it symbolically, you can probably just call the function like a function. It would look something like.
Code:
int main()
{
vector<int> x,y;
// fill x&y
derivative=Interpolation(x,y);
cout<<"The derivative at 0 is :"<<derivative(0);
return 0;
}

Once you have the numerical value for the derivative you can solve for the thermal conductivity.

Hello,

thank you for your response. Lot's of useful information here.

Finite difference methods sound like a good idea, and I know how to do this. I can use the central difference formula accurate to ##O(h^4)## and the method from interp1d to evaluate the spline at the relevant positions "interp1d.__call__()" (if I use interp1d) or use splev as I am already with splrep.

Thanks again.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
15
Views
2K
Replies
4
Views
5K
Replies
0
Views
1K
Replies
3
Views
1K
Replies
1
Views
1K
Replies
1
Views
1K
Replies
1
Views
2K
Back
Top