Differential Equation Log Plot

Hello,

I have some values from a differential equation I solved, I am trying to plot the y-axis as a logarithmic. However, I am unsure how to go about this approach:

For reference, I have this example solution from an ODE:

4×5 Matrix{Float64}:
 -1.0       -1.0  -1.0  -1.0  0.0
 -1.0       -1.0  -1.0   0.0  0.0
 -1.0       -1.0   0.0   0.0  0.0
  6.022e23   0.0   0.0   0.0  0.0

4×5 Matrix{Float64}:
 -1.0       -1.0           -1.0            -1.0          0.0
 -1.0       -1.0           -1.0             9.89029e-11  1.90176e-17
 -1.0       -1.0         1681.92            0.00290038   1.72268e-10
  6.022e23   2.86406e17     4.22592e10  12482.0          0.000225923

4×5 Matrix{Float64}:
 -1.0         -1.0            -1.0            -1.0         8.82245e-23
 -1.0         -1.0            -1.0             3.17651e-9  1.01677e-15
 -1.0         -1.0         13455.3             0.046406    5.53283e-9
  6.02199e23   5.72812e17      1.69037e11  99855.6         0.00361477

4×5 Matrix{Float64}:
 -1.0         -1.0            -1.0         -1.0         2.74788e-21
 -1.0         -1.0            -1.0          2.40525e-8  1.34756e-14
 -1.0         -1.0         45411.7          0.23493     4.18945e-8
  6.02199e23   8.59217e17      3.80332e11   3.37012e5   0.0182998

4×5 Matrix{Float64}:
 -1.0         -1.0         -1.0         -1.0         2.03916e-20
 -1.0         -1.0         -1.0          1.01311e-7  7.5085e-14
 -1.0         -1.0          1.07642e5    0.742494    1.76463e-7
  6.02199e23   1.14562e18   6.76145e11   7.98843e5   0.0578362

4×5 Matrix{Float64}:
 -1.0         -1.0         -1.0         -1.0        1.00515e-19
 -1.0         -1.0         -1.0          3.0907e-7  2.88244e-13
 -1.0         -1.0          2.10239e5    1.81273    5.38336e-7
  6.02199e23   1.43203e18   1.05648e12   1.56024e6  0.141202

I have made a function to acquire only the indices which are positive (IE: The -1’s are skipped), so I have this statement to try and create my plot.

plot(sol, idxs = plottingIndices, ylims = (0, 6.022e23), xlims = (0, tspan_end), yscale=:log10)

However, I am confused how exactly to proceed from here. Every time I try to plot with this, I receive issues due to the 0s and -1s from the initial state of the array.

Warning: Invalid negative or zero value 0.0 found at series index 1 for log10 based yscale
Warning: Invalid negative or zero value -1.0 found at series index 1 for log10 based yscale

If anyone has any ideas how to solve this issue, I would greatly appreciate it!

Avoid 0 in limit. So, you are giving ylim = (0, 6.022e23) and want to apply yaxis = :log10. These both together are cause of issue because value of ‘log(0)’ is not defined. To solve it, you can rather give ylim = (z, 6.022e23) where z is some non zeros small value (around lowest value in your data).

Similarly for negative values, it will go in complex space.

1 Like