Plot of integral curves not showing all of them

Dear all,

I have tried to solve this initial value problem

ty' + 2y = 4t^{2}

y(1) = 2

I plot it with this code:

using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = x^(2) + (1 / x^(2))

p = plot(f, -1, 5, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
    bottom_margin=10mm, label=L"t^{2} + \frac{c}{t^{2}}", framestyle=:zerolines,
    legend=:outerright)

for i = 1:0.5:3
    g(x) =  x^(2) + (i / x^(2))
    plot!(p, g, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

for i = 1:0.5:3
    g(x) =  x^(2) - (1 / x^(2))
    plot!(p, g, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

display(p)

My plot is missing a lot of curves…
Capture d’écran_2022-10-23_00-30-57

The book can plot it nicely:
Capture d’écran_2022-10-23_00-35-58

I wonder how to plot like the book with Julia. Thanks

Here is what I get:

I did a minor change of your code, but I don’t think that is the reason for the difference:

f(x) = x^2 + 1/x^2

p = plot(f, -2,2, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
    bottom_margin=10mm, label=L"t^{2} + \frac{c}{t^{2}}", framestyle=:zerolines,
    legend=:outerright)

    for i = 1:0.5:3
        g(x) =  x^(2) + (i / x^(2))
        plot!(g, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
            bottom_margin=10mm, label="", framestyle=:zerolines,
            legend=:outerright)
    end

    for i = 1:0.5:3
        g(x) =  x^(2) - (1 / x^(2))
        plot!(g, xticks=false, xlims=(-2, 2), ylims=(-2, 4),
            bottom_margin=10mm, label="", framestyle=:zerolines,
            legend=:outerright)
    end

    plot!()

I used the “jupyter” plug-in to VSCode.

1 Like

I still get half curves instead of one like yours, I think the problem is the JupyterLab I am using, or I am still using Julia 1.7.3

I try on REPL to plot and I get better result:

Capture d’écran_2022-10-23_01-22-22

Merci beaucoup!!!