【发布时间】:2023-03-27 13:45:01
【问题描述】:
这里是朱莉娅纽比! (请对我放轻松,原谅我糟糕的英语和我的编程技能)。
我正在开发一个 Julia (1.3.1) 项目。 (我正在使用 Jupyter)。 这是关于光学的;多缝衍射。 (使用夫琅禾费衍射)。 我想得到一个显示衍射图案的非常酷的图。 我快到了,但我的情节有问题,它会弹出下一条消息: “MethodError: no method matching /(::Int64, ::typeof(r))”当我尝试绘制它时。
这是我的代码。
using Pkg
Pkg.add("Plots")
Pkg.add("Plotly")
Pkg.add("Interact")
using Plots
plotly()
theme(:juno)
ϵ= 8.8541878176* 10^-12
a = 1 #Distancia del centro de una rendija al centro de la siguiente
b = 1 #Ancho de una rendija
k = 1 #Constante
R = 1 #Distancia de la rendija central a la fuente
n = 1 #Número de rendijas
P = a*(n/2)+b/2 #Calcula la "altura" de la fuente
p= P:-0.1:-P #Determina la altura de incidencia de los rayos
function r(p) #Calcula la distancia de la fuente a un punto de la rendija
sqrt(R^2+p^2)
end
function Θ(r)
acosd(R/r)
end
@.α = (a*k*sind(Θ(r(p))))/2
@.β = (b*k*sind(Θ(r(p))))/2
function Ir(d, Α, Β)
(1/2)*(ϵ*b/d)^(2)*sinc(Β)^(2)*((sind(n*Α)^2)/(sind(Α)^2))
end
plot.(Θ(r),Ir(r(p),α,β))
我在每一行都迈出了第一步;我正在打印结果以确保它以我想要的方式“工作”。 在最后一行,(即“plot.(Θ(r),Ir(r(p),α,β))”行),它显示了下一条消息;
MethodError: no method matching /(::Int64, ::typeof(r))
Closest candidates are:
/(::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}, !Matched::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}) at int.jl:59
/(::T, !Matched::T) where T<:Integer at int.jl:57
/(::R, !Matched::S) where {R<:Real, S<:Complex} at complex.jl:328
...
Stacktrace:
[1] Θ(::Function) at .\In[218]:2
[2] top-level scope at In[306]:1
顺便说一句,对于一个很酷的情节有什么建议吗? 我将使用(如果我的代码可以工作的话)“交互”包,这个包可以帮助我让用户更改狭缝的数量和其他参数吗?
非常感谢你们,伙计们。作为一个超级新手程序员,我非常感谢您的建议。
【问题讨论】: