在数学方程式中出现语法错误,我很确定问题不在括号内

问题描述 投票:-1回答:1

我在第29行的数学方程式中不断收到语法错误,我无法想象为什么。即使我用整数替换代码中的变量,我仍然收到语法错误。

我正在寻找镜头的焦距。

作为参考,镜头焦距的公式为1 / f = 1 /图像+ 1 /物体

import math

nprime = 1.6
n = 1.33
h = 2   # mm
d = 120 # mm

# YOUR CODE HERE
# raise NotImplementedError()

#first I need to rearrange the equation (n1/obj) + (n2-n1)/R = n2/img
# this gives me R = (n2-n1)(img/n2 + obj/n1)

R = ((nprime-n)*((12/n)+(30/nprime)))*2 
# not sure why I have to multiply by 2, but the numbers work out close to     what I'm supposed to get 

power = (nprime-n)/R

#######################################
# BFL Equations
#######################################

u = math.sqrt(((d-h)**2)+(R**2))
uPrime = math.sqrt((300**2)+(R**2))

# f = y/(u-u')
z_img = (nprime)/(((nprime-n)/R)-(nprime/(d-h))

f = ((1/z_img)+(1/(d-h)))**-1
print(f)

BFL = (R/(-u+uPrime))*1000
FFL = (R/(u-uPrime))*1000

print("The power is %.0f diopters" % (power*1000))
print("The radius of the rod end is %.2f mm" % R)
print("The BFL   is located %5.0f mm from the surface" % BFL)
print("The FFL   is located %5.0f mm from the surface" % FFL)
print("The transverse magnification is %.2f" % m)
python math
1个回答
0
投票
import math 
nprime = 1.6
n = 1.33
h = 2   # mm
d = 120 # mm

# YOUR CODE HERE
# raise NotImplementedError()

#first I need to rearrange the equation (n1/obj) + (n2-n1)/R = n2/img
# this gives me R = (n2-n1)(img/n2 + obj/n1)

R = ((nprime-n)*((12/n)+(30/nprime)))*2 
# not sure why I have to multiply by 2, but the numbers work out close to     what I'm supposed to get 

power = (nprime-n)/R

#######################################
# BFL Equations
#######################################
u = math.sqrt(((d-h)**2)+(R**2))
uPrime = math.sqrt((300**2)+(R**2))

# f = y/(u-u')
z_img = (nprime)/(((nprime-n)/R)-(nprime/(d-h)))

f = ((1/z_img)+(1/(d-h)))**-1
print(f)

BFL = (R/(-u+uPrime))*1000
FFL = (R/(u-uPrime))*1000

print("The power is %.0f diopters" % (power*1000))
print("The radius of the rod end is %.2f mm" % R)
print("The BFL   is located %5.0f mm from the surface" % BFL)
print("The FFL   is located %5.0f mm from the surface" % FFL)
#print("The transverse magnification is %.2f" % m)
© www.soinside.com 2019 - 2024. All rights reserved.