Reputation: 105
My question is about why do I get this error if I have defined all variables as Float64. There shouldm't be a problem.
Here is the code and the message I get
pr = Array{Float64}(1001)
succ = Array{Float64}(1001)
pr1 = Float64
pr2 = Float64
pr3 = Float64
pr4 = Float64
pr5 = Float64
succ1 = Float64
succ2 = Float64
succ3 = Float64
succ4 = Float64
succ5 = Float64
pr1 = 100,0
pr2 = 80,0
pr3 = 50,0
pr4 = 30,0
pr5 = 0,0
succ1 = 0,5
succ2 = 0,6
succ3 = 0,85
succ4 = 0,95
succ5 = 1
x = Float64
for x = 1:1:1001
pr[x]= (x-1)/10
if pr[x] == pr5
succ[x] = succ5
elseif pr[x] < pr4
succ[x] = succ4 + (succ5 - succ4) * (pr5 - pr[x]) / (pr4-pr5)
elseif pr[x] < pr3
succ[x] = succ3 + (succ4 - succ3) * (pr4 - pr[x]) / (pr3-pr4)
elseif pr[x] < pr2
succ[x] = succ2 + (succ3 - succ2) * (pr3 - pr[x]) / (pr2-pr3)
elseif pr[x] < pr1
succ[x] = succ1 + (succ2 - succ1) * (pr2 - pr[x]) / (pr1-pr2)
elseif pr[x] == pr1
succ[x] = succ1
end
println(succ[x])
end
It has to do probably with integers and floating types but I do not see how as i have defined everything as Float64
Upvotes: 0
Views: 3185
Reputation: 8044
Don't do this: pr1 = Float64
. You may think this defines pr1
to be of type Float64
, but you actually define pr1
as an alias for the type name Float64
. Just do pr1 = 100.0
and Julia will know it is a Float64
. You probably want to declare that assignment const
though, const pr1 = 100
, if you don't change it.
Also, you cant use ,
as a decimal separator in Julia. pr1 = 100,0
sets the value of pr1
to the Tuple (100,0)
.
Upvotes: 5