White Dwarf Star Coupled Runge-Kutta

Click For Summary

Discussion Overview

The discussion revolves around the application of a coupled fourth order Runge-Kutta method to model the structure of white dwarf stars. Participants are addressing issues related to the implementation of the method in C code, particularly focusing on the correctness of the code and the mathematical expressions used.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses uncertainty about the application of the Runge-Kutta method, noting that the initial results are "ridiculous."
  • Another participant points out that the code is not written in standard C but rather in a variant referred to as C-tran, suggesting that this may not be the primary issue.
  • Concerns are raised about the integer division in the expression "2/3" resulting in zero, indicating a potential source of error in the calculations.
  • It is noted that the expressions for the derivatives f0, f1, f2, and f3 appear inconsistent, which could lead to further complications in the results.
  • A participant acknowledges the need to define fractions as floats or doubles to avoid integer division issues.
  • There is a discussion about the use of the pow() function in C, with one participant suggesting that its usage is a weakness in scientific computing within the language.

Areas of Agreement / Disagreement

Participants express differing views on the correctness of the code and the mathematical expressions used. There is no consensus on the resolution of the issues raised, and multiple competing perspectives on the coding approach and mathematical formulation remain.

Contextual Notes

Participants have not fully resolved the mathematical steps or assumptions underlying the implementation of the Runge-Kutta method. The discussion highlights potential limitations in the code and the mathematical expressions without providing definitive corrections.

snelson989
Messages
3
Reaction score
0

Homework Statement


Use a coupled fourth order Runge-Kutta, to find the structure of white dwarf stars.
I think I am applying the Runge-kutta method wrong?
Variables defined in C code notes

Homework Equations


Equations in c code. and in attached images.

The Attempt at a Solution


This is the code for running through the 4th order runge kutte once, I have not done this repeatedly yet, as the numbers I get for the first run are ridiculous.
I have used a non relativistic approximation.

double rho0, rho1, rho2, rho3, rho4, f0, f1, f2, f3, h=6.626068*pow(10,-34), me=9.10938188*pow(10,-31), mp=1.67262158*pow(10,-27), pi=3.14159265,
r0, r1, r2, r3, g0, g1, g2, g3, dr=1, rhoc, G=6.67300*pow(10,-11), m0, m1, m2, m3, m4;
/* rho# values of density for Runge-Kutta method.
f# values of the derivative of pressure with respect to density used in Runge-Kutta method.
me electron mass
mp photon mass
h Plancks constant
r# radii for Runge-Kutta method
g# derivative of mass with respect to radius for Runge-Kutta method.
dr increase in radius with Runge-Kutta step
drho increase in density with Runge-Kutta step.
rhoc central density
m# mass contained in the star integrated up to that point
G gravitational constant
*/

for( r0=pow(10,-10), rho0=pow(10,10), m0=(4/3)*pi*pow(10,-20); rho0>=0; rho0=rho4, r0=r3)
{
g0=4*pi*r0*r0*rho0;
f0=(-1*(48*me*(pow(mp,(5/3))))/(h*h*(pow(2,1/3))*(pow((3*rho0/pi),(2/3)))))*G*rho0*m0/(r0*r0);

r1=r0+dr/2;
r2=r0+dr/2;
r3=r0+dr;

m1=m0+g0*dr/2;
rho1=rho0+f0*dr/2;
g1=4*pi*r1*r1*rho1;
f1=(-1/(h*h*(pow(2,1/3))*(pow((3*rho1/pi),(2/3)))/(48*me*(pow(mp,(5/3))))))*G*rho1*m1/(r1*r1);

m2=m0+g1*dr/2;
rho2=rho0+f1*dr/2;
g2=4*pi*r2*r2*rho2;
f2=(-1/(h*h*(pow(2,1/3))*(pow((3*rho2/pi),(2/3)))/(48*me*(pow(mp,(5/3))))))*G*rho2*m2/(r2*r2);


m3=m0+g2*dr/2;
rho3=rho0+f2*dr/2;
g3=4*pi*r3*r3*rho2;
f3=(-1/(h*h*(pow(2,1/3))*(pow((3*rho3/pi),(2/3)))/(48*me*(pow(mp,(5/3))))))*G*rho3*m3/(r3*r3);

m4=m0+(g0+2*g1+2*g2+g3)*dr/6;
rho4=rho0+(f0+2*f1+2*f2+f3)*dr/6;
printf("%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n", rho0, rho1, rho2, rho3, rho4, f0, f1, f2, f3, r0, r1, r2, r3, g0, g1, g2, g3, m0, m1, m2, m3, m4);
system("PAUSE");
}

fprintf(fout,"%f\t%f\t%f\n", m4, rho4, r3);
system("PAUSE");
exit(0);
}
 

Attachments

  • ScreenHunter_01 Oct. 17 18.45.gif
    ScreenHunter_01 Oct. 17 18.45.gif
    1.3 KB · Views: 554
  • ScreenHunter_02 Oct. 17 18.45.gif
    ScreenHunter_02 Oct. 17 18.45.gif
    1.2 KB · Views: 572
  • ScreenHunter_03 Oct. 17 18.45.gif
    ScreenHunter_03 Oct. 17 18.45.gif
    772 bytes · Views: 595
Physics news on Phys.org
First off, you are not writing in C. You are writing in C-tran.

That, however, is not your problem.

One problem is that 2/3 = 1/3 = 0.

Another is that your expression for f0 looks very different from your expressions for f1, f2, and f3.
 
D H said:
First off, you are not writing in C. You are writing in C-tran.

That, however, is not your problem.

One problem is that 2/3 = 1/3 = 0.

Another is that your expression for f0 looks very different from your expressions for f1, f2, and f3.

thankyou, I assume that I need to define the fractions as floats or doubles.
however I think that although the functions for f0 etc look different I have simply swapped a pow(x,-1) for explicitly doing that operation, although I may well be wrong I have changed many functions in an a ttempt to isolate the problem.

Thankyou You've finally solve a weeks anguish of me struggling with this.
 
You're welcome.

It is your willy-nilly usage of pow() that made me say you are writing C-tran. That C has a pow() function as opposed to an exponential operator is one of the key weaknesses of C/C++ when it comes to scientific computing. pow(a,b) is typically evaluated as exp(b*ln(a)). The function is something to avoid if at all possible.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
10
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 10 ·
Replies
10
Views
13K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
7K