请问我这个代码哪里错了呀。。

#
d=0.05
f=20000
nmd=1500/f
N=60
sita=0:0.001:2*pi
sita0=0
R=abs( sin(N*pi*d.*sin(sita-sita0)./nmd)./N./sin(pi*d.*sin(sita-sita0)./nmd) )

ERROR: LoadError: MethodError: no method matching -(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Int64)
Closest candidates are:
-(::Complex{Bool}, ::Real) at complex.jl:298
-(::Missing, ::Number) at missing.jl:97
-(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107

Stacktrace:
[1] top-level scope at none:0
in expression starting at untitled-2852f8afe3f501470eb9f409e95560b4:8

julia> sita-sita0
ERROR: MethodError: no method matching -(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Int64)
Closest candidates are:
  -(::Complex{Bool}, ::Real) at complex.jl:303
  -(::Missing, ::Number) at missing.jl:115
  -(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107
  ...
Stacktrace:
 [1] top-level scope at REPL[10]:100 

julia> sita .- sita0
0.0:0.001:6.283
1 个赞

谢谢谢谢,是个思路!

@. 可以写得更漂亮些:

R=abs(@.(sin(N*pi*d*sin(sita-sita0)/nmd) /N /sin(pi*d*sin(sita-sita0)/nmd)))

还有 sin 也没有作用于数组的方法,你解决了 - 后应该还会出它的错。

解决啦,把sin换成sin.就行了