user167195
user167195

Reputation: 33

Incrementation in Julia

I want to solve this integration. With the upper limit phi ranging from 1-2.4. I want to receive answers at every increment of phi.

The code that I have pasted below is only outputting the answer when phi=2.4. How can I fix this? I am new to Julia and have basic knowledge of programming which is why i think i am not doing this correctly.

using Ranges
for ϕ in range(start=1, stop=2.4, step=0.2)
    using QuadGK
    f(ϕ) = ϕ*(cos(ϕ)/sin(ϕ))
    a = 0
    b = ϕ
    I,est = quadgk(f, a, b, rtol=1e-8)
end
println(I, est)

Upvotes: 3

Views: 109

Answers (1)

Lorenzo Bassetti
Lorenzo Bassetti

Reputation: 945

Print should be inside the for loop, so you print all the iterations ...

using Ranges
using QuadGK

f(ϕ) = ϕ*(cos(ϕ)/sin(ϕ))

for ϕ in range(start=1, stop=2.4, step=0.2)
    a = 0
    b = ϕ
    I,est = quadgk(f, a, b, rtol=1e-8)
    println(I, est)
end

Upvotes: 1

Related Questions