Re: [Tutor] Hi there, have a question for a side project in physics.....
On Mon, Dec 25, 2017 at 09:45:35AM +, Alan Gauld via Tutor wrote: > On 25/12/17 09:08, Siddharth Sehgal wrote: > > >physics masters student. I am trying to use the Sellmeier Equation > > >I originally state them as floats. However such a process apparently > > >cannot be done with "floats" like these. > > It can be done just with a large error (although as a physics > grad you will know how to calculate the error I assume) I don't think the numbers or equation is so ill-conditioned that the error will be "large", or at least not larger than the experimental uncertainty in the coefficients. Floating point maths is tricky, but it isn't *that* tricky. Especially not for "reasonable" sized numbers, with only nine or ten significant figures. This is the huge advantage of IEEE-754 maths using 64-bit floats, as Python does: most of the time, the obvious formula "just works". -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi there, have a question for a side project in physics.....
On Mon, Dec 25, 2017 at 01:08:13PM +0400, Siddharth Sehgal wrote: > The actual equation is below screen shotted No it isn't -- either you forgot to attach it, or the mailing list removed it. Do you mean this equation? https://en.wikipedia.org/wiki/Sellmeier_equation I suggest you try using Python and compare your results to those from here: http://www.calctool.org/CALC/phys/optics/sellmeier or from some authoritative source of refractive indexes. Here is my simple test, for borosilicate glass BK7 using the values from Wikipedia. Using the website: refractive index at 590 nm = 1.51670 Using Python, I get: 1.516698697993053 Here is my code. Feel free to use it for any purpose, no credit required (except as needed to meet any academic obligations you may have about collaboration and/or plagiarism). import math def sellmeier(lambd, B1, B2, B3, C1, C2, C3): return 1 + B1*f(lambd, C1) + B2*f(lambd, C2) + B3*f(lambd, C3) def f(x, y): x2 = x**2 return x2/(x2 - y) # Coefficients for BK7 (borosilicate crown glass) result = sellmeier(0.590, # 590nm == 0.590µm 1.03961212, 0.231792344, 1.01046945, 6.00069867e-3, 2.00179144e-2, 103.560653) print(math.sqrt(result)) -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi there, have a question for a side project in physics.....
On Mon, Dec 25, 2017 at 01:08:13PM +0400, Siddharth Sehgal wrote: > Hi there > > > I am a novice python user and am a physics masters student. I am > trying to use the Sellmeier Equation to calculate a refractive index. > The coefficients of this equation are decimals to a large number of > sig figs ( i.e B1 = 1.03961212, B2 = 0.231792344, C1 = 6.00069867×10−3 That's not really a lot of significant figures. Python floats are C 64-bit doubles, so they can represent about 15 or 16 significant figures. The numbers you show are only 9 or 10. > ... and so on) in the sellmeier formula there is a lot of fractions, > multiplication and squaring of these numbers. I originally state them > as floats. However such a process apparently cannot be done with > "floats" like these. What makes you think that you cannot use floats for this? Of course floating point maths on computers is not the same as real arithmetic of the Real numbers in mathematics class, and you may need to carefully consider the possible error conditions in your equations, round-off error, and so forth, but in general I would expect that simply using Python as a calculator will be fine for all but the most precise calculations. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Hi there, have a question for a side project in physics.....
On 25/12/17 09:08, Siddharth Sehgal wrote: physics masters student. I am trying to use the Sellmeier Equation I originally state them as floats. However such a process apparently > cannot be done with "floats" like these. It can be done just with a large error (although as a physics grad you will know how to calculate the error I assume) What do i do? PLEASE NEED HELP! There ae several ways and I guess the best will involve using SciPy/numpy features. But since i don't know those I'll suggest the old school way which is to multiply your numbers up until they become integers and take advantage of pythons big int feature. You will need to plug all the multipliers into your formula and work out the final multiplier - but that is just exponent arithmetic so should be doable. Finally adjust your answer by the calculated exponent. As I say there will probably be better solutions in the numpy space and hopefully someone else will tell you about them. The actual equation is below screen shotted This list does not permit non-text attachments - the server throws them away. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Hi there, have a question for a side project in physics.....
Hi there I am a novice python user and am a physics masters student. I am trying to use the Sellmeier Equation to calculate a refractive index. The coefficients of this equation are decimals to a large number of sig figs ( i.e B1 = 1.03961212, B2 = 0.231792344, C1 = 6.00069867×10−3 ... and so on) in the sellmeier formula there is a lot of fractions, multiplication and squaring of these numbers. I originally state them as floats. However such a process apparently cannot be done with "floats" like these. What do i do? PLEASE NEED HELP! The actual equation is below screen shotted Many thanks, I look forward to your response, THIS IS NOT HOMEWORK BY THE WAY, I just want to use this program as it saves a lot of writing on paper. Siddharth Sehgal MSc Student in Physics SUNY - Stony Brook University ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor