Ndsolve of random (periodic) initial conditions via BSplineFunction

Suppose we want to solve the heat equation for a random initial temperature field T(t,x,y). Therefore I define the initial conditions with the BSplineFunction which nicely incorporates periodic boundary conditions and try to solve it with NDSolve:

Clear["Global`*"] Lx = 1; Ly = 1; eq = D[T[t, x, y], t] == Laplacian[T[t, x, y], {x, y}]; pbc1 = T[t, x, 0] == T[t, x, Ly]; pbc2 = T[t, 0, y] == T[t, Lx, y]; T0[x_, y_] =   BSplineFunction[RandomReal[1, {30, 30, 1}], SplineClosed -> True][x,    y] Plot3D[T0[x, y], {x, 0, Lx}, {y, 0, Ly}, PlotRange -> All,   AxesLabel -> {"x", "y", "T"}, ColorFunction -> "DarkRainbow",   Mesh -> All, MeshStyle -> Opacity[.2]] T0[0, 0] ic = T[0, x, y] == T0[x, y] ic2 = T[0, x, y] == 0.5*Exp[-4 ((x - Lx/2)^2 + (y - Ly/2)^2)]; Monitor[AbsoluteTiming[   sol = NDSolve[{eq, pbc1, pbc2, ic},      T, {t, 0, 1}, {x, 0, Lx}, {y, 0, Ly},      Method -> {"MethodOfLines",        "SpatialDiscretization" -> {"TensorProductGrid",          "MaxPoints" -> 25}},      EvaluationMonitor :> (currentTime =         Row[{"t = ", CForm[t]}])]], currentTime] 

The code unfortunately throws an error "Data … is not a rectangular tensor with dimensions …". I assume this results from the fact that T0 evaluated e.g. at grid point [0,0] returns a list {} and NDSolve probably needs just the float value.

I tried T0[0,0][[1]] which yields the expected value. But this does not work for the definition of the initial condition: ic = T[0, x, y] == T0[x, y][[1]], where x,y are not set yet. This returns just x, in reality it should first put in the values of x,y and only after that take list element 1 (if I am not mistaken).

Apart from that the code works fine which can be verified if you simply use ic2 instead of ic as initial condition in NDSolve.

Can someone help to get this running?

Can you apply Hex damage when the target is immune to the initial damage?

The Warlock is fighting a Ochre Jelly. On his turn, he cast Hex on the Jelly as a bonus action, then hits it with his Short sword. The Ochre Jelly is immune to the slashing damage, so the attack does zero damage regardless of what the Warlock rolls, however is the Hex able to proc, and deal 1d6 necrotic damage to the jelly?

Hex states (PHB p.251):

You place a curse on a creature that you can see within range. Until the spell ends, you deal an extra 1d6 necrotic damage to the target whenever you hit it with an attack. […]

So although the attack hit, would the Jelly still take the Hex’s additional damage when it is immune to the original damage of the attack?

If the Feywild Shard magic item’s Wild Magic Surge results in a spell, does that replace the initial triggering spell, or occur in addition to it?

Tasha’s Cauldron of Everything (p. 127) includes a magic item called the Feywild shard. The relevant part of its description states:

When you use a Metamagic option on a spell while you are holding or wearing the shard, you can roll on the Wild Magic Surge table in the Player’s Handbook. If the result is a spell, it is too wild to be affected by your Metamagic, and if it normally requires concentration, it doesn’t require concentration in this case; the spell lasts for its full duration.

This part is the one that some in my group don’t agree on:

  • My reading: You cast a spell that is being affected by Metamagic. You then choose to roll on the table. If the resulting effect listed on the table is then also a spell, it is separate from the original spell and has the two listed added conditions (Metamagic can’t be used on it, and it doesn’t require concentration).
  • The others think that if the result of the roll on the Wild Magic Surge table is a spell, it replaces the original spell, and the original Metamagic option you chose doesn’t affect it.

Which interpretation is correct?

NMinimize differential evolution: how do search points and initial points really work?

I am puzzled by the settings of a specific method for NMinimize called DifferentialEvolution, given for example here. The settings include both "SearchPoints", or the size of the population of evolving points, and "InitialPoints", or the initial population(?). What I don’t quite understand is that "SearchPoints" can be set to a value different from the number of specified "InitialPoints" and NMinimize will often happily proceed, and sometimes it won’t.

What might be happening under the hood? If there are less "InitialPoints" than there are "SearchPoints", will the population be filled up with random points to meet the specified number of "SearchPoints" before evolution begins or does it proceed with a population that is in fact smaller than "SearchPoints"? What about the opposite case?

Here is an example where we give much less "InitialPoints" than there are "SearchPoints".

Clear[f, c, v, x1, x2, y1, y2, y3]; f = 2 x1 + 3 x2 + 3 y1/2 + 2 y2 - y3/2; c = {x1^2 + y1 == 5/4, x2^(3/2) + 3 y2/2 == 3, x1 + y1 <= 8/5,     4 x2/3 + y2 <= 3, y3 <= y1 + y2, 0 <= x1 <= 10, 0 <= x2 <= 10,     0 <= y1 <= 1, 0 <= y2 <= 1,     0 <= y3 <= 1, {y1, y2, y3} \[Element] Integers}; v = {x1, x2, y1, y2, y3};  NMinimize[{f, c}, v, Method -> "DifferentialEvolution"] (*{7.66718, {x1 -> 1.11803, x2 -> 1.31037, y1 -> 0, y2 -> 1, y3 -> 1}}*)  points = 5; searchpoints = 50; listpoints = {RandomReal[{0, 10}, points],  RandomReal[{0, 10}, points], RandomReal[{0, 1}, points],  RandomReal[{0, 1}, points],  RandomReal[{0, 1}, points]}\[Transpose];  NMinimize[{f, c}, v,   Method -> {"DifferentialEvolution", "SearchPoints" -> searchpoints,  "InitialPoints" -> listpoints}] (*{7.66718, {x1 -> 1.11803, x2 -> 1.31037, y1 -> 0, y2 -> 1, y3 -> 1}}*) 

If there are more "InitialPoints" than there are "SearchPoints", NMinimize sometimes works and sometimes doesn’t, depending on the value of the random seed for instance.

How important is initial state for local search optimisation?

I have been enjoying Pascal van Hentenryck’s Discrete Optimisation course and we’re in Week 4 on the wonders of Local Search algorithms for combinatorial optimisation.

I’m wondering how important the initial configuration is to the quality of solution achievable in a fixed time or, somewhat equivalently, how quickly a solution of a given quality can be reached.

So if I have a good heuristic or intuition for how to arrange things in the first place, is it helpful to devote some processing time to setting that up or is it all dominated by the effect of the local search process?

For example, in the Cartesian Travelling Salesman Problem (where we’re working in a 2D plane and the cost of a journy is simply the straight-line distance) I might "feel" that a good route could roughly follow a clockwise sweep from the centre of the space. So I could use this to set my initial tour (i.e. order the nodes by their angle from the mean of all points). This intuition might be rubbish for certain instances and great for others, I was hoping to see a study where (let’s say random TSP) instances had been solved by following a heuristic first state as opposed to a completely random (but legal) first state.

How long is the initial “training time” to get the first level of a class?

Consider a 0th level character, or a character with existing character levels, multi-classing into a new one.

I think, she needs to go somewhere – to a fighters’ school, or to a wizards guild, etc – and need to pass a training. It is highly world-, class- and DM-dependent.

But how long time does it take?

I ask this in the hope, that there is a rule, or at least a hint in a rulebook. What needs to be done to get a new class, it varies, but how long does it take, I think it has (or should have) at least a hint somewhere. I don’t know even the magnitude – is it some weeks, or decades?

Solution to User Initial HTTP Requests Unencrypted Despite HTTPS Redirection?

It is my understanding that requests from a client browser to a webserver will initially follow the specified protocol e.g, HTTPS, and default to HTTP if not specified (Firefox Tested). On the server side it is desired to enforce a strict type HTTPS for all connections for the privacy of request headers and as a result HTTPS redirections are used. The problem is that any initial request where the client does not explicitly request HTTPS will be sent unencrypted. For example, client instructs browser with the below URL command.


google.com will redirect the client browser to use HTTPS but the initial HTTP request and GET parameters were already sent unencrypted possibly compromising the privacy of the client. Obviously there is nothing full-proof that can be done by the server to mitigate this vulnerability but:

  1. Could this misuse compromise the subsequent TLS security possibly through a known-plaintext
    attack (KPA)?
  2. Are there any less obvious measures that can be done to mitigate this possibly through some DNS protocol solution?
  3. Would it be sensible for a future client standard to always initially attempt with HTTPS as the default?

Approximate solution of a nonlinear ODE in the form of a Fourier series containing the coefficients of the initial ODE

In this topic we considering nonlinear ODE:

$ \frac{dx}{dt}= (x^4) \cdot a_1 \cdot sin(\omega_1 \cdot t)-a_1 \cdot sin(\omega_1 \cdot t + \frac{\pi}{2})$ – Chini ODE

And system of nonlinears ODE:

$ \frac{dx}{dt}= (x^4+y^4) \cdot a_1 \cdot sin(\omega_1 \cdot t)-a_1 \cdot sin(\omega_1 \cdot t + \frac{\pi}{2})$

$ \frac{dy}{dt}= (x^4+y^4) \cdot a_2 \cdot sin(\omega_2 \cdot t)-a_2 \cdot sin(\omega_2 \cdot t + \frac{\pi}{2})$

Chini ODE’s NDSolve in Mathematica:

pars = {a1 = 0.25, \[Omega]1 = 1} sol1 = NDSolve[{x'[t] == (x[t]^4) a1 Sin[\[Omega]1 t] - a1 Cos[\[Omega]1 t], x[0] == 1}, {x}, {t, 0, 200}] Plot[Evaluate[x[t] /. sol1], {t, 0, 200}, PlotRange -> Full] 

System of Chini ODE’s NDSolve in Mathematica:

pars = {a1 = 0.25, \[Omega]1 = 3, a2 = 0.2, \[Omega]2 = 4} sol2 = NDSolve[{x'[t] == (x[t]^4 + y[t]^4) a1 Sin[\[Omega]1 t] - a1 Cos[\[Omega]1 t], y'[t] == (x[t]^4 + y[t]^4) a2 Sin[\[Omega]2 t] - a2 Cos[\[Omega]2 t], x[0] == 1, y[0] == -1}, {x, y}, {t, 0, 250}] Plot[Evaluate[{x[t], y[t]} /. sol2], {t, 0, 250}, PlotRange -> Full] 

There is no exact solution to these equations, therefore, the task is to obtain an approximate solution.

Using AsymptoticDSolveValue was ineffective, because the solution is not expanded anywhere except point 0.

The numerical solution contains a strong periodic component; moreover, it is necessary to evaluate the oscillation parameters. Earlier, we solved this problem with some users as numerically: Estimation of parameters of limit cycles for systems of high-order differential equations (n> = 3)

How to approximate the solution of the equation by the Fourier series so that it contains the parameters of the original differential equation in symbolic form, namely $ a_1$ , $ \omega_1$ , $ a_2$ and $ \omega_2$ .