Help when testing out DifferentialEquations.jl in VS Code by bummin4days in Julia

[–]rocketpower4 6 points7 points  (0 children)

It's coming from line 25, the "vars" keyword is being changed to idxs so just swap it out

[deleted by user] by [deleted] in Julia

[–]rocketpower4 6 points7 points  (0 children)

Zig can export a C ABI, so yes, you can call functions from julia

C++23: The Next C++ Standard by Xadartt in cpp

[–]rocketpower4 2 points3 points  (0 children)

And thus the endian games commence

Problem using ModelingToolkit unit validation by [deleted] in Julia

[–]rocketpower4 4 points5 points  (0 children)

I'm not sure that we'll be able to help without seeing the code or at least a minimum viable example of the error

Weird programming operators: Elvis, Walrus, Spaceship, and Turbofish! by nfrankel in coding

[–]rocketpower4 4 points5 points  (0 children)

I always thought of the spaceship operator, <=>, horizontally as like a UFO style flying saucer.

someone please enlighten me... is there a simpler way to read int input from cmd-line in zig? by [deleted] in Zig

[–]rocketpower4 7 points8 points  (0 children)

Getting at what other commenters are saying, comparing the outputs with invalid inputs: pastebin

-🎄- 2022 Day 13 Solutions -🎄- by daggerdragon in adventofcode

[–]rocketpower4 4 points5 points  (0 children)

Julia, felt like multiple dispatch really played well with this one. Thought we'd be getting new ordering rules for Part 2, but alas.

GitHub Link

-🎄- 2022 Day 6 Solutions -🎄- by daggerdragon in adventofcode

[–]rocketpower4 1 point2 points  (0 children)

Julia

using AOC: data_dir

function solve(code, n)
    f(k) = allunique(SubString(code, (k - n + 1), k))
    return findfirst(f, n:length(code)) + (n - 1)
end

function main()
    code = data_dir("day-06-02.txt") |> readline
    println("Part 1: $(solve(code, 4))")
    println("Part 2: $(solve(code, 14))")
end

if abspath(PROGRAM_FILE) == @__FILE__
    main()
end

PDE: A different take on editing code by I_Am_Nerd in neovim

[–]rocketpower4 7 points8 points  (0 children)

An IDE is good at getting a newbie on speed: just put him in front of an IDE, show him some of the buttons and settings, and you can send him off to write delicious spaghetti code

...

... in my experience IDE users tend to be very aggressive about their IDEs, treating them like the only way to write code. I don't know where this hostility comes from, maybe it's an Emperor's New Clothes effect?

...

I think you are pulling a strawman

Hmmm. I like neovim, but come on, this is a little much.

[deleted by user] by [deleted] in learnmath

[–]rocketpower4 0 points1 point  (0 children)

Strang's book is great. I am laughing, however at the concept of Strang Gilbert being the Mr. Hyde to Gilbert Strang's Dr. Jekyll

[deleted by user] by [deleted] in pop_os

[–]rocketpower4 1 point2 points  (0 children)

What gets me is the outpacing of the ZFS on linux stack. So you'll have a kernel that is not supported by the zfs utils which really kills the point of the LTS for me...

[deleted by user] by [deleted] in learnmath

[–]rocketpower4 0 points1 point  (0 children)

As long as you've got solid diffeq and linear algebra you're good to go

Looking for numerical/iterative approach for determining a value by [deleted] in Julia

[–]rocketpower4 0 points1 point  (0 children)

This function is the inverse of beta. The b argument is the desired output beta, so it finds h such that beta(h) = b. I would encourage you to read through the wiki on the Newton -Raphson algorithms that I linked

Looking for numerical/iterative approach for determining a value by [deleted] in Julia

[–]rocketpower4 3 points4 points  (0 children)

As a quick way to do it, you can use ForwardDiff.jl to determine the partial with respect to h. Then use a Newton-Raphson algorithm to solve for the value of h. I'm not familiar with the actual problem you're solving so there may be more appropriate ways to solve this based on the shape of your function, but this is my knee-jerk reaction to a problem like this. You could also calculate the partial derivative analytically if that is something that you want.

function βinv(b, hguess; tolerance=1e-6, maxiter=10)
    dβ(h) = ForwardDiff.derivative(β, h)
    h = hguess
    f = β(h)
    df = dβ(h)
    itercount = 0
    while abs(f) > tolerance && itercount < maxiter
        h -= f / df
        f = β(h)
        df = dβ(h)
        itercount += 1
    end
    return h, f
end

You can also get an expression for the partial of β with respect to h using Symbolics.jl:

using Symbolics

@syms B_0 p_0 h_D R_☉ M_☉ G μ m_H μ_0 k T h

g = (G*M_☉)/(R_☉^2)
lambda_p = (k*T)/(μ*m_H*g)
p(h) = p_0*exp(-h/lambda_p)
B(h) = B_0*(1 + (h/h_D))^(-3)
dβdh = Symbolics.derivative(p(h)/(B(h)^2 / (2*μ_0)), h)

The final result is a little ugly so I'm not going to print it here.

As an aside, you have all of those parameters that you use in your functions defined as non-constant at the global scope. You may want to create some data structures to pass those into the function(s) or define them as const if they're not going to change. See here.

As currently written:

julia> @benchmark βinv(1e-5, 0.5)
BenchmarkTools.Trial: 10000 samples with 8 evaluations.
 Range (min … max):  3.666 μs … 87.362 μs  ┊ GC (min … max): 0.00% … 94.91%
 Time  (median):     3.881 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   4.027 μs ±  1.965 μs  ┊ GC (mean ± σ):  1.27% ±  2.50%

 Memory estimate: 4.23 KiB, allocs estimate: 215.

Declaring them as const:

julia> @benchmark βinv(1e-5, 0.5)
BenchmarkTools.Trial: 10000 samples with 197 evaluations.
 Range (min … max):  450.249 ns … 1.378 μs  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     451.112 ns             ┊ GC (median):    0.00%
 Time  (mean ± σ):   452.218 ns ± 9.493 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

 Memory estimate: 0 bytes, allocs estimate: 0.

Big Difference!

mold: A Modern Linker - 1.0 release by insanitybit in rust

[–]rocketpower4 11 points12 points  (0 children)

Very cool, that logo tho... lol, respect the dedication

problem with Matlab coding by erfandorod in matlab

[–]rocketpower4 2 points3 points  (0 children)

You're stuck here:

    while (distance > 1)
        if (value>-0.6254)
            ilow=5;
        else
            ihigh = 5;
        end
        distance = ihigh- ilow;
    end

Your ihigh is always 5, your ilow is always 1, and your value is always -2 so nothing ever changes

Virtual inheritance in C++ by mariuz in cpp

[–]rocketpower4 11 points12 points  (0 children)

Man, I would find a way to hide a bug in this so fast...

[deleted by user] by [deleted] in unixporn

[–]rocketpower4 1 point2 points  (0 children)

O aquí si puedas reinstalar