Acheiving "lookAt" functionallity with cframe.fromMatrix

The wiki states what when using cframe.lookAt in order to orient a cframe to a specific point, that you may experience “numerical instabillity” once a pitch angle of 90 degrees is reached. Therefore, cframe.fromMatrix is recommended. I am currently experiencing issues relating to this, so I have been attempting to use cframe.fromMatrix to acheive the same functionallity. However, I’ve currently gotten nowhere in trying to find a solution. It always seems like I get returned unrealistic values. Unfortunately I have extremely little knowledge with matrices, though I do understand some vector mathematics. I would appreciate it if anyone could point me in the right direction. Thanks.

local function visualiseBeam(nodes)
    for i = 1, #nodes - 1 do
        local thisNode = nodes[i]
        local nextNode = nodes[i+1]

        local beam = partPool[i] or createBeam()
        local nodeDistance = (nextNode - thisNode).Magnitude
        beam.Size = Vector3.new(0.2, 0.2, nodeDistance)
        -- Note : I don't even know what I'm doing here....
        beam.CFrame = CFrame.fromMatrix(
            Vector3.new(thisNode),
            Vector3.new(1, 0, 0),
            Vector3.new(0, 1, 0),
            nextNode - thisNode) .Unit
        ) * CFrame.new(0, 0, -nodeDistance / 2)
    end

end

CFrame.lookAt allows you to specify the default up vector (0,1,0) now, which means if you’re nearing 90° pitch you swap it with a different up vector like (1,0,0) which prevents that instability.