differential equations – Finding an analytic solution with a JacobiSD function

We are searching for an analytic solution to the given equation for $f_text{n}(u)$, for $u in (0, d/2)$ (this problem is a snippet from this paper here)
$$-partial^2_{u} f_text{n} + leftlbrack 1 – f_text{n} ^{2} +frac{j_{u}^2}{f_text{n} ^4}rightrbrack
f_text{n} = 0$$

With a little manipulation (integrate from 0 to $x$, use that $f’$ is minimal at $x=0$…):

$$left(frac{partial f_n^2}{partial u}right)^2 = 2 (f_n^2 – f^2_0) left( f_n^2 (2 – f_n^2 – f^2_0) + frac{2j_u^2}{f^2_0}right)$$

or more usefully:
$$ 2left(frac{partialPsi}{partial u}right)^2 = left( (Psi^2 + f_0^2) (2 – Psi^2 – 2f^2_0) + frac{2j_u^2}{f^2_0}right)$$.

I know from extensive hand-calculation that this has a Jacobi elliptic function solution.

$$Psi_n^2 = f_n^2 – f_0^2 = frac{b_n^2 a_n^2}{a_n^2 + b_n^2} operatorname{sd}^2left(u sqrt{frac{a_n^2 + b_n^2}{2}}, sqrt{frac{b_n^2}{a_n^2 + b_n^2}}right)$$

where
$$
a_n^2 = – left(1-frac{3}{2}f_0^2right) + sqrt{2left(1-frac{1}{2}f_0^2right)^2 + frac{2j_u^2}{f_0^2}}
\
b_n^2 = + left(1-frac{3}{2}f_0^2right) + sqrt{2left(1-frac{1}{2}f_0^2right)^2 + frac{2j_u^2}{f_0^2}}
$$

When I try and replicate this in Mathematica, I obtain a different solution:

an^2 == - ( 1 - (3/2) f0^2) + Sqrt(2 (1 - f0^2/2)^2 + 2 ju^2/f0^2)
bn^2 == + ( 1 - (3/2) f0^2) + Sqrt(2 (1 - f0^2/2)^2 + 2 ju^2/f0^2)
eqn = {Sqrt(2)*Psi'(x) == Sqrt((an^2 + Psi(x)^2)*(bn^2 - Psi(x)^2))}
sol = DSolve(eqn, Psi(x), x)

Output:
{{Psi(x) -> bnJacobiSN((Sqrt(2)anx + 2an*C1)/2, -(bn^2/an^2))}}

It is not clear to me that these solutions are equivalent, and moreover, the form looks completely different, let alone being a completely different JEF solution. I have only looked into DSolve in the past, but I am not too sure how to use Reduce to find a better solution.
Any advice would be gratefully accepted. My end result is that I want to find the analytic solution, ideally able to find the results for $a_n$ and $b_n$ as well, but I appreciate mathematical manipulation is somewhat necessary!

bash – Finding if the first and last column of a string is empty

I have string with a pattern like maze, I want to check if the first and last columns of the string is not empty. I tried using the loop to check if the last character before new line is empty or not, but that logic is not working.

Mylar = “- - - - - - - - - - - -
        - - - - -  - - -  - - -
        - - — — - - - — - 
        .- - - - - - - - - - —
        - - - - - - - - - - - -”

The string has rows and columns and size of rows and columns can be any size. The string consists only of spaces and “-“. there is no separation between two adjacent characters

if [ "$str" == "$nl" ] ;
nl='
'

this is inside a loop that check all the characters.

algorithms – Time complexity of finding median in data stream

I was reading a solution to the problem in the title on leetcode and the article says that the time complexity of the following solution is O(n)

  1. setup a data structure to hold stream value and insert new element in the right place using linear search or binary search
  2. return median

my solution is as follows:

class MedianFinder:

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.arr = ()
        

    def addNum(self, num: int) -> None:
        idx = bisect.bisect_left(self.arr, num)
        self.arr.insert(idx, num)

    def findMedian(self) -> float:
        # self.arr.sort()
        if len(self.arr) % 2 != 0:
            return self.arr(len(self.arr)//2)
        else:
            return (self.arr(len(self.arr)//2 -1) + self.arr(len(self.arr)//2 ))/2

My question is about the time complexity of the push method. the binary search will take O(log n) to find the index. the insert will take O(n). but since the method will be called on the stream, will the complexity be O(n^2) or O(n) ?

enter image description here

I am not finding my project form goggle cloud platform. Now I want to retrieve my project

I used the google cloud free trial. I am not finding my project now for due payment. I paid google due amount But now I am not finding my existing VM instance. I have no project backup. This project and database are very important for me. I want back my project. Please help me. I spend 1 almost 1 year building that project. I paid all the due amount. I was not able to pay for the crisis of money. Please help me.

python – Finding the Euclidean distance between the vectors of matrix a, and vector b

Here is the problem,

Given a 2D numpy array ‘a’ of sizes n×m and a 1D numpy array ‘b’ of
size m. You need to find the distance(Euclidean) of the ‘b’ vector
from the rows of the ‘a’ matrix. Fill the results in the numpy array.
Follow up: Could you solve it without loops?

a = np.array(((1, 1),
              (0, 1),
              (1, 3),
              (4, 5)))
b = np.array((1, 1))
print(dist(a, b))
>>(0,1,2,5)

And here is my solution

import math


def dist(a, b):
    distances = ()
    for i in a:
        distances.append(math.sqrt((i(0) - b(0)) ** 2 + (i(1) - b(1)) ** 2))
    return distances


a = np.array(((1, 1),
              (0, 1),
              (1, 3),
              (4, 5)))
print(dist(a, (1, 1)))

I wonder how can this be solved more elegant, and how the additional task can be implemented.

algorithms – Finding all pairs of points with no point in between

Suppose there are $n$ points $p_1,p_2,dots,p_n$ with color red or blue on a line. We want to find all pairs $(p_i,p_j)$ whose color is distinct and such that there are no points between them. If there are $k$ pairs with the described property, design an algorithm with $O(nlog k)$ that uses idea of divide and pruning.

I think if we check all points we can solve this problem, but running time will exceed $O(nlog k)$.

I think for solving this problem we can use projective geometry duality, but I am stuck. Any help would be appreciated.

algorithms – Finding distinct pairs in geometric settings

Suppose there are $n$ points $p_1,p_2,…,p_n$ with color red or blue on a line. We want to find all pairs $(p_i,p_j)$ their color is distinct and there are no points between theme. If there are $k$ pairs with described design an algorithm with $O(nlog k)$ that use idea divide and pruning.

I think if we check all point we can solve this problem , but running time is not $O(nlog k)$.

I think for solving this problem we can use the duality that present in this page

But i get stuck to solve my problem. any help be appreciated.