Astrophysics programs

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
hsilop
Posts: 33
Joined: Thu Mar 14, 2019 12:35 am
Location: Canberra, Australia

Astrophysics programs

Here is my current suite of Astrophysics programs. You must first execute 00 to initialize the set of constants the programs refer to. If anybody knows how I can get this program to run automatically, that'd be great. I just run it once and save the calculator state so all the variables are setup correctly. But there has to be a cleaner way to do this! Surely?

Single value functions - these functions take the current value in the X register as input and return the result in the X register leaving the rest of the stack untouched. Running each function after pressing the SHIFT key will perform the inverse operation.

swarzR - Returns the Schwarzschild radius ( in Metres ) of the black hole of mass in kg
ISCO - Returns the Innermost Stable Circular Orbit ( in Metres ) of a black hole of mass in kg
bhF - Returns the frequency of a spinning black hole ( in Hertz ) for a Kerr black hole of mass in kg
PCtoM - Converts Parsecs to Metres
LYtoM - Converts Lightyears to Metres
gamma - Return the Lorentz factor for the velocity in units of c
KtoC - Converts degrees Kelvin to Degrees Celcius

Multi value programs. Each of these programs prompts for input and pushes the returned value on the stack as it was before the program was called.

Dist - Returns the distance to a star of given flux and luminosity
Flux - Returns the flux of a given star of luminosity and distance given
Lumin - Returns the luminosity of a star of given flux and distance
Temp - Returns the temperature of a planet of given albedo and distance from star of a given luminosity
Ve - Return the escape velocity of an astronomical body of given mass and radius

Constants defined and accessible by pressing RCL at any time. You can do it while a program is running too since I don't use the VARMENU input method. ( VARMENU prevents values being recalled via RCL - which sux ).

solR - Radius of the Sun
solM - Mass of the Sun
solL - Luminosity of the Sun
teraA - Albedo of the Earth
teraM - Mass of the Earth
teraR - Radius of the Earth
G - The Gravitational Constant
c - The speed of light in a vacuum
AU - One Astronomical Unit
pc - One parsec
ly - One lightyear
KC - Number of degrees of add to degrees Kelvin to return degrees Celcius
stefB - Stefan Boltzmann constant

Variables use in the code. ( Can be handy when doing multiple calculations. )

lumin - Luminosity
flux - Flux
dist - Distance
mass - Mass
units, unit2,uabbrev - Used by display function to display result with appropriate units

Bon Appetit.

Code: Select all

``````00 { 2052-Byte Prgm }
01▸LBL 00
02 "COMMON CODE"
03 4
04 1
05 DIM "STACK"
06 149597870700
07 STO "AU"
08 299792458
09 STO "c"
10 667408ᴇ-16
11 STO "G"
12 198847ᴇ25
13 STO "solM"
14 3828ᴇ23
15 STO "solL"
16 6955ᴇ5
17 STO "solR"
18 59722ᴇ20
19 STO "teraM"
20 6378100
21 STO "teraR"
22 0.306
23 STO "teraA"
24 5.670374419ᴇ-8
25 STO "stefB"
26 DEG
27 RCL "AU"
28 648ᴇ3
29 ×
30 PI
31 ÷
32 STO "pc"
33 RCL "c"
34 365.2425
35 ×
36 24
37 ×
38 3600
39 ×
40 STO "ly"
41 273.15
42 STO "KC"
43 RTN
44▸LBL "STKPSH"
45 INDEX "STACK"
46 INSR
47 R↑
48 STOEL
49 J+
50 R↑
51 STOEL
52 J+
53 R↑
54 STOEL
55 J+
56 R↑
57 STOEL
58 RTN
59▸LBL "STKPOP"
60 INDEX "STACK"
61 STO ST L
62 RCLEL
63 ENTER
64 →
65 ENTER
66 →
67 ENTER
68 →
69 DELR
70 X<> ST L
71 RTN
72▸LBL "DISPLAY"
73 CF 00
74 X<0?
75 SF 00
76 ABS
77 1ᴇ6
78 FIX 02
79 X<Y?
80 SCI 02
81 R↓
82 0.1
83 X>Y?
84 SCI 02
85 R↓
86 FS? 00
87 +/-
88 CF 00
89 CLA
90 ARCL ST X
91 ├" "
92 ARCL "units"
93 ARCL "unit2"
94 ├" ("
95 ARCL "uabbrev"
96 ├")"
97 AVIEW
98 CLA
99 ASTO "units"
100 ASTO "unit2"
101 ASTO "uabbrev"
102 RTN
103▸LBL "WATTS"
104 "Watts"
105 ASTO "units"
106 "W"
107 ASTO "uabbrev"
108 XEQ "DISPLAY"
109 RTN
110▸LBL "MPERS"
111 "Velo"
112 ASTO "units"
113 "city"
114 ASTO "unit2"
115 "m/s"
116 ASTO "uabbrev"
117 XEQ "DISPLAY"
118 RTN
119▸LBL "METRES"
120 "Metres"
121 ASTO "units"
122 "m"
123 ASTO "uabbrev"
124 XEQ "DISPLAY"
125 RTN
126▸LBL "WSQM"
127 "Flux"
128 ASTO "units"
129 "W/M/M"
130 ASTO "uabbrev"
131 XEQ "DISPLAY"
132 RTN
133▸LBL "PARSEC"
134 "Parsec"
135 ASTO "units"
136 "pc"
137 ASTO "uabbrev"
138 XEQ "DISPLAY"
139 RTN
140▸LBL "CELSIUS"
141 "Cel"
142 ASTO "units"
143 "sius"
144 ASTO "unit2"
145 "°C"
146 ASTO "uabbrev"
147 XEQ "DISPLAY"
148 RTN
149▸LBL "KELVIN"
150 "Kelvin"
151 ASTO "units"
152 "°K"
153 ASTO "uabbrev"
154 XEQ "DISPLAY"
155 RTN
156▸LBL "Hz"
157 "Hertz"
158 ASTO "units"
159 "Hz"
160 ASTO "uabbrev"
161 XEQ "DISPLAY"
162 RTN
163▸LBL "LIGHTY"
164 "Light"
165 ASTO "units"
166 "years"
167 ASTO "unit2"
168 "ly"
169 ASTO "uabbrev"
170 XEQ "DISPLAY"
171 RTN
172▸LBL "MASS"
173 "kg"
174 ASTO "uabbrev"
175 "Kilo"
176 ASTO "units"
177 "grams"
178 ASTO "unit2"
179 XEQ "DISPLAY"
180 RTN
181▸LBL "ISCO"
182 XEQ "STKPSH"
183 CLA
184 ARCL ST X
185 FC? 64
186 GTO 01
187 ├" m"
188 AVIEW
189 PSE
190 "ISCOm"
191 AVIEW
192 PSE
193 XEQ "ISCOm"
194 RTN
195▸LBL 01
196 ├" kg"
197 AVIEW
198 PSE
199 XEQ "swazR"
200 3
201 ×
202 XEQ "METRES"
203 XEQ "STKPOP"
204 RTN
205▸LBL "ISCOm"
206 XEQ "STKPSH"
207 XEQ "swazM"
208 3
209 ÷
210 XEQ "MASS"
211 XEQ "STKPOP"
212 RTN
213▸LBL "swazR"
214 XEQ "STKPSH"
215 CLA
216 ARCL ST X
217 FC? 64
218 GTO 01
219 ├" m"
220 AVIEW
221 PSE
222 "swarzM"
223 AVIEW
224 PSE
225 XEQ "swazM"
226 RTN
227▸LBL 01
228 ├" kg"
229 AVIEW
230 PSE
231 RCL "G"
232 ×
233 2
234 ×
235 RCL "c"
236 X↑2
237 ÷
238 XEQ "METRES"
239 XEQ "STKPOP"
240 RTN
241▸LBL "bhF"
242 XEQ "STKPSH"
243 RCL "c"
244 FS? 64
245 GTO 03
246 "Mass "
247 ARCL ST Y
248 ├" kg"
249 GTO 04
250▸LBL 03
251 CLA
252 ARCL ST Y
253 ├" Hz"
254▸LBL 04
255 AVIEW
256 PSE
257 3
258 Y↑X
259 X<>Y
260 ÷
261 RCL "G"
262 ÷
263 PI
264 ÷
265 4
266 ÷
267 FC? 64
268 GTO 01
269 "bhM"
270 AVIEW
271 PSE
272 XEQ "MASS"
273 GTO 02
274▸LBL 01
275 XEQ "Hz"
276▸LBL 02
277 XEQ "STKPOP"
278 RTN
279▸LBL "swazM"
280 RCL "c"
281 X↑2
282 ×
283 2
284 ÷
285 RCL "G"
286 ÷
287 XEQ "MASS"
288 RTN
289▸LBL "PCtoM"
290 CLA
291 ARCL ST X
292 FC? 64
293 GTO 01
294 ├" m"
295 AVIEW
296 PSE
297 "MtoPC"
298 AVIEW
299 PSE
300 XEQ "MtoPC"
301 "AVIEW"
302 PSE
303 RTN
304▸LBL 01
305 ├" pc"
306 AVIEW
307 PSE
308 XEQ "STKPSH"
309 RCL "pc"
310 ×
311 XEQ "METRES"
312 XEQ "STKPOP"
313 RTN
314▸LBL "Lumin"
315 ENTER
316 XEQ "STKPSH"
317 INPUT "dist"
318 INPUT "flux"
319 RCL "dist"
320 X↑2
321 RCL "flux"
322 ×
323 4
324 ×
325 PI
326 ×
327 XEQ "WATTS"
328 XEQ "STKPOP"
329 RTN
330▸LBL "Ve"
331 XEQ "STKPSH"
332 INPUT "mass"
334 2
335 RCL "G"
336 ×
337 RCL "mass"
338 ×
340 ÷
341 SQRT
342 XEQ "MPERS"
343 XEQ "STKPOP"
344 RTN
345▸LBL "Flux"
346 ENTER
347 XEQ "STKPSH"
348 INPUT "lumin"
349 INPUT "dist"
350 RCL "lumin"
351 RCL "dist"
352 X↑2
353 ÷
354 4
355 ÷
356 PI
357 ÷
358 STO "flux"
359 XEQ "WSQM"
360 XEQ "STKPOP"
361 RTN
362▸LBL "Dist"
363 ENTER
364 XEQ "STKPSH"
365 INPUT "lumin"
366 INPUT "flux"
367 RCL "lumin"
368 RCL "flux"
369 ÷
370 4
371 ÷
372 PI
373 ÷
374 SQRT
375 XEQ "METRES"
376 XEQ "STKPOP"
377 RTN
378▸LBL "Temp"
379 ENTER
380 XEQ "STKPSH"
381 INPUT "albedo"
382 INPUT "lumin"
383 INPUT "dist"
384 RCL "albedo"
385 +/-
386 1
387 +
388 RCL "lumin"
389 ×
390 16
391 ÷
392 PI
393 ÷
394 RCL "stefB"
395 ÷
396 RCL "dist"
397 X↑2
398 ÷
399 0.25
400 Y↑X
401 XEQ "KELVIN"
402 XEQ "STKPOP"
403 RTN
404▸LBL "KtoC"
405 FC? 64
406 GTO 01
407 "CtoK"
408 PSE
409 XEQ "CtoK"
410 RTN
411▸LBL 01
412 RCL "KC"
413 -
414 XEQ "CELSIUS"
415 RTN
416▸LBL "CtoK"
417 RCL "KC"
418 +
419 XEQ "KELVIN"
420 RTN
421▸LBL "MtoPC"
422 XEQ "STKPSH"
423 RCL "pc"
424 ÷
425 XEQ "PARSEC"
426 XEQ "STKPOP"
427 RTN
428▸LBL "LYtoM"
429 CLA
430 ARCL ST X
431 FC? 64
432 GTO 01
433 ├" m"
434 AVIEW
435 PSE
436 "MtoLY"
437 AVIEW
438 PSE
439 XEQ "MtoLY"
440 RTN
441▸LBL 01
442 ├" ly"
443 AVIEW
444 PSE
445 XEQ "STKPSH"
446 RCL "ly"
447 ×
448 XEQ "METRES"
449 XEQ "STKPOP"
450 RTN
451▸LBL "MtoLY"
452 XEQ "STKPSH"
453 RCL "ly"
454 ÷
455 XEQ "LIGHTY"
456 XEQ "STKPOP"
457 RTN
458▸LBL "gamma"
459 FC? 64
460 GTO 01
461 "v"
462 AVIEW
463 PSE
464 XEQ "v"
465 RTN
466▸LBL 01
467 XEQ "STKPSH"
468 X↑2
469 +/-
470 1
471 +
472 SQRT
473 1/X
474 XEQ "DISPLAY"
475 XEQ "STKPOP"
476 RTN
477▸LBL "v"
478 XEQ "STKPSH"
479 X↑2
480 1/X
481 +/-
482 1
483 +
484 SQRT
485 XEQ "LIGHTV"
486 XEQ "STKPOP"
487 RTN
488▸LBL "LIGHTV"
489 "Light"
490 ASTO "units"
491 "speed"
492 ASTO "unit2"
493 "c"
494 ASTO "uabbrev"
495 XEQ "DISPLAY"
496 RTN
497 END
``````
DM42 SN: 03223

HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65

Walter
Posts: 1025
Joined: Tue May 02, 2017 9:13 am
Location: Close to FRA, Germany

Re: Astrophysics programs

Merci bien for sharing.

I assume KC being 273.15 ?
DM42 SN: 00041 --- Follower of Platon.

HP-35, HP-45, ..., HP-50, WP 34S, WP 31S, DM16L

Joe Horn
Posts: 9
Joined: Thu Oct 04, 2018 12:10 am

Re: Astrophysics programs

Walter wrote:
Sat Jul 13, 2019 12:15 pm
Merci bien for sharing.

I assume KC being 273.15 ?
Yes; see program steps 41 and 42.

hsilop
Posts: 33
Joined: Thu Mar 14, 2019 12:35 am
Location: Canberra, Australia

Re: Astrophysics programs

I probably should also point out that the single value functions are designed to be assigned to a key and used in CUSTOM mode. That way you can press the yellow shift key before the assigned key to invoke the inverse operation. Each program announces this by briefly showing the inverse functions name.

Also, each single value function briefly displays the input value together with its unit abbreviation. All programs display their final result together with the units and unit abbreviation. This is important when studying physics because the units are just as valuable as the numeric result.
DM42 SN: 03223

HP11C, HP12C, HP15C, HP16C, HP25, HP32S, HP33C, HP41CV, HP46, HP65