Die Suche ergab 6 Treffer

von Homer.Simpson
Donnerstag 21. März 2013, 15:43
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

Re: A simple code problem

Thank you all, for your hints. I *will* try to stop posting and fix my code with your suggestions.


Bests
von Homer.Simpson
Donnerstag 21. März 2013, 15:33
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

Re: A simple code problem

@Homer.Simpson:

`r = pylab.arange(10.0, 20000.0, dr)` is the very first line in your function. At that time Python does not know about the name `dr`. But it is used for the definition of `r`. This is why the error is thrown.


Thanks for your replay. But can you first have a look in to one post ...
von Homer.Simpson
Donnerstag 21. März 2013, 15:19
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

Re: A simple code problem

@Homer.Simpson: No you didn't. The only line where you assigned something to that name is line 38 and that ist 8 lines *after* you tried to use it the first time.

You are right. But I don't use it till I define it in line 38 (or better to say 39). I define "r" in line 31, but the code doesn't ...
von Homer.Simpson
Donnerstag 21. März 2013, 14:40
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

Re: A simple code problem

/me hat geschrieben: The error is quite clear.

Code: Alles auswählen

 r = pylab.arange(10.0, 20000.0, dr)
You use dr, but you haven't defined it before trying to use it.
Hi \me

It is not true, if you have a look in to line 34 I have defined it before using it.
von Homer.Simpson
Donnerstag 21. März 2013, 14:36
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

Re: A simple code problem

Sorry guys for inappropriate style :( . In fact I'm new in python or in other words I do not write in python. I need to run this code to understand the physics behind it.
I will try to fix the point which you have mentioned.

Bests
von Homer.Simpson
Donnerstag 21. März 2013, 14:15
Forum: Allgemeine Fragen
Thema: A simple code problem
Antworten: 12
Zugriffe: 1229

A simple code problem

Hi everybody

I have a simple code as follow:


import pylab
from scipy.integrate import odeint
from scipy.constants import pi, G, c, hbar, m_n

Msun=1.98892e30
Gamma0 = 5.0/3.0
K0 = (3.0*pi**2)**(2.0/3.0)*hbar**2/(5.0*m_n**(8.0/3.0))
Gamma1 = 3
rho1 = 5e17
P1 = K0*rho1**Gamma0
K1 = P1/rho1 ...