If-else loop failure for a large array

Sh_166
Thu, 06 Apr 2023 13:51:28 +0000
General Usage

I have the following code:

    if sol[5,i] - sol_1[5,i] >= 0.0
        s[i] = sol[5,i] - sol_1[5,i]
    else
        s[i] = sol_1[5,i] - sol[5,i]
    end
end

Now, here, sol and sol_1 correspond to 2 solutions I have from DifferentialEquations.jl (basically, I would like to plot the absolute value of the difference at each timestep; my solution vectors are same sized and have 6 variables - here, I am only considering the 5th variable).

Now, problem with this is that the code doesn’t work. I get both positive and negative values for s which certainly not what I intended. In fact, I ran the following line,

s = sol[5,i] - sol_1[5,i]

This and the above code give me the same s. Any help would be appreciated!

6 posts - 4 participants