This calculation is part of an assignment for a class I am taking. I need to calculate the incident power from a modified blackbody distribution. My professor is not familiar with Sage, and so I would like to be able to print clear and concise results so that he can read them without having to disect the code.
I need to make a correction factor so that the definite integral of the blackbody distribution from 280 nm to 4000 nm is 1000 instead of about ~1310 . I first integrate the equation:
and then solve for the correction factor. I start out by setting up the upper and lower bounds of the integral.
Using a print statement for the above equations is fine because the units don't have any special characters, superscripts, or subscripts. When I need to print something more complex, however, I can't get the formatting right.
As you can see, the units for W/m^2 are in plain text instead of being nicely formatted. I have tried several things to get both the value of the calculation and the properly displayed units, but have not found a satisfactory solution. Here are my attempts.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-6a45769e534f> in <module>()
2
3 print 'There is ' + str(solarBB) + latex('W/m^2') + ' of solar radiation between 280 nm and 4000 nm in a BB at ' + str(Ts) + ' K.'
----> 4 print 'There is ' + str(solarBB) + show('W/m^2') + ' of solar radiation between 280 nm and 4000 nm in a BB at ' + str(Ts) + ' K.'
5 print 'There is ' + str(solarBB) + show(latex('W/m^2')) + ' of solar radiation between 280 nm and 4000 nm in a BB at ' + str(Ts) + ' K.'
TypeError: cannot concatenate 'str' and 'NoneType' objects
There is 1309.73965576525 of solar radiation between 280 nm and 4000 nm in a BB at 5760 K.
Can't have more than one line of text dummy!
There is 1309.73965576525 of solar radiation between 280 nm and 4000 nm in a BB at 5760 K. No new lines allowed. Nope. ewline Not for all the gold in Fort Knox.
Works, but I only get the last line again.
I wish I could just use a Markdown cell and report:
There is {{solarBB}} of solar radiation between 280 nm and 4000 nm in a BB at {{Ts}} K.
I think this would work if I had access to the IPython extension python-markdown.js. I did get it to work in a Sage notebook with HTML printint, but I am so invested in this now I can't let it go. It would still be handy to have access to variables and equations in from a Sage or Jupyter notebook in Markdown cells to avoid having to retype everything twice. I feel like this would work really well with Sage since everything is required to have a Latex representation anyway.
I might also be unaware of a simple solution, I'm pretty new to Sage and Python.