Numerical instabilities in a solution to a partial differential equation

I have been trying to solve a partial differential equation known as KdV (Korteweg-de Vries) equation using NDSolve.
KdV equation is written as:

$frac{partial u(x,t)}{partial t}+frac{partial^3 u(x,t)}{partial x^3}=-6u(x,t)frac{partial u(x,t)}{partial x}$

One of the analytical solution of this equation is a Jacobi elliptical function
$u_{A} = text{A JacobiCN}(B*(x- c t),m)^2$
where A, B, c and m are known parameters.

So the initial condition is
$u_0 = text{A JacobiCN}(B*x,m)^2 $.

The boundary condition is: $u(t,-a) = u(t,a)$.

Code for analytical solution is

a = 30; m = 0.9; A = 0.9;
B = Sqrt(1.5*A) / Sqrt(2*m + m^2)
c = 6*(-A + A*m + A*m^2)/(m*(2 + m))
uA(x_,t_) := A*JacobiCN(B*(x - c*t), m)^2;
Plot(uA(x,0.5), {x, -a, a}, LabelStyle ->  Directive(14, Bold,   Black), AxesLabel -> {Style("x", 14, Bold, Black), Style("uA", 14, Bold, Black)}) 

Plot of analytical solution for t = 0.5

enter image description here

When I solve the partial differential equation using NDSolve, the numerical instabilities arise and the numerical solution doesn’t match the analytical solution.

eq = {D(u(x, t), {t, 1}) + D(u(x, t), {x, 3}) == -6 u(x, t) D(u(x, t), {x, 1}), u(x, 0) == A*JacobiCN(B*x, m)^2, u(-a, t) == u(a, t)};
sol = Flatten@NDSolve(eq, u, {t, 0, 1}, {x, -a, a})
Plot(Evaluate(u(x, 0.5) /. sol), {x, -a, a}, LabelStyle ->  Directive(14, Bold, Black), AxesLabel -> {Style("x", 14, Bold, Black), Style("u", 14, Bold, Black)})

enter image description here

I am also getting the warning message
NDSolve::mxsst: Using maximum number of grid points 10000 allowed by the MaxPoints or MinStepSize options for independent variable x.
I have tried different options and methods given in NDSolve documentation and also tried solutions given in https://mathematica.stackexchange.com/questions/9277/i-failed-to-solve-a-set-of-one-dimension-fluid-mechanics-pdes-with-ndsolve/9291#9291 but nothing seems to be working.
Following method removed the warning message but there was no improvement in the numerical solution.

nxy = 500;
sol = Flatten@NDSolve(eq, u, {t, 0, 1}, {x, -a, a}, Method -> {"MethodOfLines", 
     "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> nxy, "MinPoints" -> nxy, 
       "DifferenceOrder" -> "Pseudospectral"}, Method -> "Adams"}, MaxSteps -> (Infinity))

Why does Solve give me an expression with root in it for this equation?

“12.0.0 for Microsoft Windows (64-bit) (April 6, 2019)”

This can be solved by hand without too much difficulty. But

Solve({s == 8/27 ((Sqrt(1 + (3/2 t)^2))^3 - 1), t > 0}, t, Reals)

results in

{{t -> ConditionalExpression(
    Root(-16 s - 27 s^2 + 16 #1^2 + 36 #1^4 + 27 #1^6 &, 2), s > 0)}}

machine learning – What n means in neural network equation?

I’ve found this equation that explains the output of a neuron in a MLP network:

$y(n) = f(mathbf{w}^T mathbf{x}(n) + b)$

I can understand the general context, but since i have no background with mathematical notation, i don’t understand what the $(n)$ parameter means (e.g. $y(n)$, $x(n)$). Is it sort of a temporal or sample index? I’ve seen this notation in other machine learning subjects, but didn’t find an explanation.

Thanks in advance,

na.numerical analysis – Solving equation for higher degree of composition

Given this function f(x) = x – 1/x .

the equation f(f(x)) = x has two solutions : $frac{1}{sqrt{2}}$, $frac{-1}{sqrt{2}}$ , but how about solving this equation for a higher degree of composition , for example f(f(….(f(x)))) = x ( 15 times ) , what is the mathematical tool needed in order to solve this equation

equation solving – how to solve system of polynomials restricted to positive reals?

I’m new to Mathematica and would like to use it to solve a system of polynomials. In this system, every variable (and every solution I’m interested in) is a positive real number.

I tried this:

Solve(k1*A*N - k2*C == 0 && k3*B*N - k4*D == 0 && 
  N0 - C - D - N == 0 && A0 - C - A == 0 && B0 - D - B == 0, {A, B, C,
   D, N})

which generates an enormous expression and isn’t constrained to positive reals. I am using Mathematica 11.3.0.0 which I believe doesn’t support PositiveReals as an argument to Solve. When I try to encode the constraints as additional equations, Mathematica hangs:

Solve(k1*A*N - k2*C == 0 &&
      k3*B*N - k4*D == 0 && 
      N0 - C - D - N == 0 && 
      A0 - C - A == 0 && 
      B0 - D - B == 0 &&
      k1 >= 0 && k2 >= 0 && k3 >= 0 && k4 >= 0 && A >= 0 && B >= 0 && N >= 0 && C >= 0 && D >= 0 && A0 >= 0 && B0 >= 0 && N0 >= 0,
      {A, B, C, D, N}, Reals)

Trying to encode the constraints with Assuming also hangs:

Assuming(k1 >= 0 && k2 >= 0 && k3 >= 0 && k4 >= 0 && A >= 0 && 
  B >= 0 && N >= 0 && C >= 0 && D >= 0 && A0 >= 0 && B0 >= 0 && 
  N0 >= 0,
 Solve(k1*A*N - k2*C == 0 &&
       k3*B*N - k4*D == 0 && 
       N0 - C - D - N == 0 && 
       A0 - C - A == 0 && 
       B0 - D - B == 0,
       {A, B, C, D, N}, Reals))

any ideas on how to solve this system? I don’t expect it to have any enormously complicated solutions.

Setting up a quadratic equation

Need help setting up the equation.

enter image description here

equation solving – NDSolve with embedded FindRoot and NIntegrate

I am trying to plot results for a very simple differential equation of the form:

$$frac{partial^2 x(N,z'(N))}{partial N^2} = F(N,z'(N)), $$

where $z'(N)$ is a function of $N$ that needs to be solved using FindRoot for at every $N$ position, and $F(N,z’)$ is a nasty equation that results from a numerical integration over:

$$ F(N,z’) = int_{-infty}^{infty} expleft( -frac{x’^2}{2sigma_{x’}^2} right) F(N,z’,x’)dx’$$.

So, I put together some mathematica code but it runs terrible slow (on the order of a day or two)! I noticed there were some things that affected the speed of the code particularly the numerical coefficient in front of $F(N,z'(N))$. But I was wondering if there is any help to be given to get better/faster results! Any help would be greatly appreciated!

Note: I had to use $NN$ in place of $N$ in my equations because its a function in mathematica. Also, in the FN function I have to actually copy and paste the output of FNzprime (an ugly mess) in the integrand for it to evaluated.

(*constants*)
e = -1.60217733*10^-19;
m = 9.109389699999999*10^-31;
epsilon = 8.854187817620391*10^-12;

(*basic equations*)
rs2 = {zprime, xprime + K/(gamma*kw) Sin(kw*zprime), 0};
ro2 = {(NN + 10000)*lw, x + K/(gamma*kw) Sin(kw*(NN + 10000)*lw), 0};

betas = {beta - K^2/(4 gamma^2) Cos(2 kw*zprime),K/gamma Cos(kw*zprime), 0};
betao = {beta - K^2/(4 gamma^2) Cos(2 kw*(NN + 10000)*lw),K/gamma Cos(kw*(NN + 10000)*lw), 0};

betaDot = {(c*K^2*kw)/(2 gamma^2)Sin(2 kw*zprime), -((c*K*kw)/gamma) Sin(kw*zprime), 0};

deltar2 = ro2 - rs2;
Rgam2 = Sqrt(deltar2((1))^2 + deltar2((2))^2);
Ec2 = (e/(4 Pi*epsilon)) (deltar2/Rgam2 - betas)/(gamma^2 Rgam2^2 (1 - (deltar2/Rgam2).betas)^3);
Erad2 = (e/(4 Pi*epsilon)) Cross(deltar2/Rgam2, Cross(deltar2/Rgam2 - betas, betaDot))/(c*Rgam2*(1 - (deltar2/Rgam2).betas)^3);

Bc2 = Cross(deltar2/Rgam2, Ec2);
Brad2 = Cross(deltar2/Rgam2, Erad2);

Fbc2 = Cross(betao, Bc2);
Fbrad2 = Cross(betao, Brad2);


sumEtran = (Ec2((2)) + Erad2((2)));
sumFBtran = Fbc2((2)) + Fbrad2((2));



(*Numeric Functions*)

ZPRIME(NN_?NumericQ, x_?NumericQ, xprime_?NumericQ, gamma_, K_, kw_, beta_, sigma_, lw_) :=zprime /. FindRoot(sigma == (1/(gamma kw))Sqrt(gamma^2 + K^2) (EllipticE(kw*(NN + 10000)*lw, K^2/(gamma^2 + K^2)) - EllipticE(kw zprime, K^2/(gamma^2 + K^2))) - beta (Sqrt)(((NN + 10000)*lw - zprime)^2 + (x - xprime + (K Sin(kw *(NN + 10000)*lw))/(gamma kw) - (K Sin(kw zprime))/(gamma kw))^2), {zprime, 0})


coeff = ((e*lw^2)/(gamma*m*beta^2*c^2) (10^-10/e)/(2 Pi (30*10^-6) (10^-5)) Exp(-(sigma^2/(2 (10^-5)^2))));
FNzprime =coeff (sumEtran + sumFBtran) /. {lw -> 0.026, K -> 1, beta -> Sqrt(1 - 1/(4000/0.511)^2), gamma -> 4000/0.511, c -> 3*10^8, kw -> (2 Pi)/0.026, zprime -> ZPRIME}

FN(NN_?NumericQ, x_?NumericQ, sigma_?NumericQ) :=With({ZPRIME = ZPRIME(NN, x, 0, 4000/0.511, 1, (2 Pi)/0.026, Sqrt(1 - 1/(4000/0.511)^2), sigma, 0.026)}, 
  NIntegrate( (Exp(-(xprime^2/(2 (30*10^-6)^2)))) FNzprime, {xprime, -300*10^-6, 300*10^-6}))

sol00 = NDSolve({X''(NN) - (FN(NN, 0, 10^-8)) == 0, X(0) == 0, X'(0) == 0}, X, {NN, 0, 140})

Plot(X(NN) /. {sol00}, {NN, 0, 10}, Evaluated -> True)

equation solving – How to grab output from Reduce into a variable

I use Reduce to solve an 3rd order equation, and the output is given as the OR’d combination the solution variable. Normally, I can do a replacement to assign the value to a variable, but that doesn’t work on Reduce. I found that I need to use ToRules to do so, but I still can’t get it to work.

Vout =Vin/(C1*C2*L1*R1*s^3 + C1*R1*s + C2*L1*s^2 + C2*R1*s + 1) 
s=(ImaginaryI) (Omega);
values={
 R1->2000,
 C1 -> 10e-9,
 L1 -> 500u,
 C2 -> 1.2n
};   
 sol2=Reduce(ComplexExpand(Im(Vout/Vin/.values))==0,(Omega)) 

Here’s the output:

enter image description here

Normally, I’d do

(Omega) = (Omega) /. sol2((3))

to grab the 3rd item from the similar list resulting from a Solve function. However, Reduce doesn’t provide a list, so it doesn’t work. How do I use ToRules correcty? or is there another way to grab “any” specific output from a Reduce function?

Solve the system using elimination What are a, b, and c in the quadratic equation, ax^2+bx+c=y given the

Solve the system using elimination What are a, b, and c in the quadratic equation, ax^2+bx+c=y given the points: (2,17), (-2,9), and (1,6), please solve the question using steps e.g. (step 1, step 2)?

Logaritmic equation $log_2 log_x(x-3y)=-1$

Solve system of equations

$log_2 log_x(x-3y)=-1$

$xtimes y^{log_x y}=y^{frac{5}{2}}$

I managed to reduce second equation to

$frac{1}{log_x y} +log_x y =frac{5}{2}$

But I dont know what to do with first one.