How to obtain the same result of the same system if I write the system in different ways (NDSolve)?

I did program where I solved a system when I organized in matrix form, this is the code

Clear["Global`*"]  SeedRandom[1234]  Nmax = 5; (*Number of sites*)  tini = 0; (*initial time*)  tmax = 200; (*maximal time*)  \[Sigma]2 = 0; (*Variance*)  n0 = 5; (*initial condition*)  ra = 1; (*coupling range*)  \[Psi]ini = Table[KroneckerDelta[n0 - i], {i, 1, Nmax}];  RR = RandomReal[{-Sqrt[3*\[Sigma]2], Sqrt[3*\[Sigma]2]}, Nmax];  Z = Table[     Sum[KroneckerDelta[i - j + k], {k, 1, ra}] +       Sum[KroneckerDelta[i - j - k], {k, 1, ra}], {i, 1, Nmax}, {j, 1,       Nmax}] + DiagonalMatrix[RR];  Clear[\[Psi]]  usol = NDSolveValue[{I D[\[Psi][t], t] ==      Z.\[Psi][t], \[Psi][0] == \[Psi]ini}, \[Psi], {t, tini, tmax}]  Plot[usol[t], {t, tini, tmax}] 

Now, I´m trying to solve the same system but writing the equations

Clear["Global`*"]  tini = 0;  tmax = 200;  usol = NDSolveValue[{I x1'[t] == x2[t], I x2'[t] == x1[t] + x3[t],      I x3'[t] == x2[t] + x4[t], I x4'[t] == x3[t] + x5[t],      I x5'[t] == x4[t], x1[0] == 0, x2[0] == 0, x3[0] == 0, x4[0] == 0,      x5[0] == 1}, {x1, x2, x3, x4, x5}, {t, tini, tmax}];  Plot[usol[t], {t, tini, tmax}] 

Why the second code doesn´t give me the same result if I write the same system?

How to replace a list/array of variables in the result?


I want to know how to replace multiple variables in the result expression. To be specific, all those variables are inside the array I defined.

For a simple example, if I define input

mm5 = {a, b, c, d};

mm7 = {2, 3, 9, 8};

mm7a = mm7.mm5

Out: 2 a + 3 b + 9 c + 8 d

After that, if I define a new array

mm6 = {3, 4, 5, 7}

And I want to replace every unknown component in mm5 to be values in mm6, and to let final result of mm7a to be 23+34+95+87=119. How should I do that?

I was thinking is there anyway similar to

mm7a /. {mm5[[i]] -> mm6[[i]],{i,1,4}}

Of course, what I wrote is wrong. But is there any simple way to use /. to help me achieve this effect?? And after substituting, I want symbols in mm5 be reserved, for example, when I out put mm5 result, it is still {a, b, c, d}

I searched the whole web but I didn’t find a simple way to do it. Maybe I didn’t search it right. So I post my question here and hopefully to get some answer.

Thank you

How does Mathematica obtain this result?

FullSimplify[  Sqrt[2 \[Pi]] InverseFourierTransform[1/(x^2 - a^2), x, p],   Element[a, Reals]] 

Gives the output

-((\[Pi] Sign[p] Sin[a p])/a) 


$ \int_{-\infty }^{\infty } \frac{e^{-i k x}}{x^2-a^2} \, dx$ is not a defined integration. Mathematica also returns undefined as answer if you compute it.

So, I am trying to understand how does Mathematica calculates that Fourier transform of the non-integrable function.

Why the exported result is different from the evaluated result

enter image description here

Why the exported result is different from the evaluated result? How to set to make them the same!

Here’s the code, It needs the package MaTeX. It’s Ok, If you don’t use this package, just make sure the text remain the same size when evaluating and exporting.

\[Gamma] = 7/18 \[Pi]; a1 = Graphics3D[{Opacity[0.4], LightBlue, Sphere[], Opacity[1], Black,      Thick, Line[{{-1, 0, 0}, {1, 0, 0}}],      Line[{{0, 1, 0}, {0, -1, 0}}], Line[{{0, 0, -1}, {0, 0, 1}}]}]; a2 = ParametricPlot3D[{Cos[t], Sin[t], 0}, {t, 0, 2 \[Pi]},     PlotStyle -> {Black, Dashed}]; a3 = ParametricPlot3D[{0, Cos[t], Sin[t]}, {t, -\[Pi]/2, \[Pi]/2},     PlotStyle -> {Black, Dashed}]; a4 = ParametricPlot3D[{Cos[t], 0, Sin[t]}, {t, -\[Pi], \[Pi]},     PlotStyle -> {Black, Dashed}]; data = Table[{0, Cos[t], Sin[t]}, {t, 3 \[Pi]/2, 5 \[Pi]/4, -0.01}]; a5 = Graphics3D[{Green, Arrowheads[0.035], Arrow[Tube[data, 0.01]]}]; data = Table[{0, Cos[t], Sin[t]}, {t, \[Pi], 1.5 \[Pi]/2, -0.01}]; a6 = Graphics3D[{Green, Arrowheads[0.035], Arrow[Tube[data, 0.01]]}]; data = Table[{0, Cos[t], Sin[t]}, {t, \[Pi]/2, 3 \[Pi]/2, 0.01}]; a7 = Graphics3D[{Green, Tube[data, 0.01]}]; a8 = Graphics3D[{Green, Sphere[{0, -1, 0}, 0.05]}]; a9 = Show[{a1, a2, a3, a4, a5, a6, a7, a8}, BoxStyle -> Opacity[0],     ViewPoint -> {\[Pi], -1.4 \[Pi], \[Pi]/1.5}]; data = Table[{-Cos[t] Sin[\[Gamma]], Cos[t] Cos[\[Gamma]],      Sin[t]}, {t, (1.5 \[Pi])/2, (1.75 \[Pi])/2, 0.01}]; b1 = Graphics3D[{Green, Arrowheads[0.035], Arrow[Tube[data, 0.01]]}]; data = Table[{-Cos[t] Sin[\[Gamma]], Cos[t] Cos[\[Gamma]],     Sin[t]}, {t, (2 \[Pi])/2, (2.25 \[Pi])/2, 0.01}]; b2 =   Graphics3D[{Green, Arrowheads[0.035],     Arrow[Tube[data, 0.01]]}]; data =   Table[{-Cos[t] Sin[\[Gamma]], Cos[t] Cos[\[Gamma]],     Sin[t]}, {t, \[Pi]/2, (3 \[Pi])/2, 0.01}]; b3 =   Graphics3D[{Green, Tube[data, 0.01]}]; data = Table[{0.2 Sin[t], -0.2 Cos[t], 0}, {t, 0, \[Gamma],     0.01}]; b4 =   Graphics3D[{Red, Arrowheads[0.015], Arrow[Tube[data, 0.008]]}]; b5 =   Graphics3D[{Red,     Tube[{{0, 0, 0}, {Sin[\[Gamma]], -Cos[\[Gamma]], 0}}, 0.008]}]; b6 = Rasterize[   Show[{a9, b1, b2, b3, b4, b5}, ImageSize -> {1000, 1000}],    RasterSize -> 3000]  c1 = Graphics[    Text[MaTeX[      TeXForm[StringTemplate["\[Gamma] = ``\[Degree]"][        Floor[\[Gamma] 180/\[Pi]]]], FontSize -> 30], {0, -0.1}]]; c2 = Canvas[c1, FrameStyle -> False, PlotRange -> {{-1, 1}, {-1, 1}},    Background -> b6, ImageSize -> {1000, 1000}] Export["带闭合路径的庞加莱球   " <>     DateString[{"(Date ", "ISODate", " Time ", "Hour", "-", "Minute",       "-", "Second", ")"}] <> ".pdf", c2] // SystemOpen ```` 

put the result of a query into a variable and WITH statement

I need to put the result of a query into a variable.

Just a query, works as successful

DECLARE @count INT = (  SELECT count (*) FROM [AdventureWorks].[Person].[Address]     );  select @count; 

But if I need to use the WITH statement in a query, then I get a syntax error

DECLARE @count INT = (    WITH person_address (id)    as (     SELECT AddressID     FROM [AdventureWorks].[Person].[Address]    )    SELECT count (*)    FROM person_address     );  select @count; 

Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword ‘WITH’.

Msg 319, Level 15, State 1, Line 2 Incorrect syntax near the keyword ‘with’. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

Msg 102, Level 15, State 1, Line 9 Incorrect syntax near ‘)’.

How do I put the query value into a variable if the WITH clause is used in the SQL statement?

What balance pitfalls result from this house rule regarding levitating creatures?

My table is considering the following house rule:

A creature suspended above the ground and unable to move on its own (e.g., under the effect of the levitate spell) is especially susceptible to forces that would push or pull it. When you successfully target a suspended creature with an effect that would move it, you can choose to move it an additional number of feet equal to 5 times your relevant ability modifier (e.g., your Strength modifier if you shoved the creature with a special melee attack, or your spellcasting ability modifier if you used a magical effect, such as the gust spell or the shove effect of the Telekinetic feat). The additional movement must be in the same direction as the normal movement caused by the effect you used.

A creature with a flying speed is not affected by this rule.

The logic here should be obvious — a creature hanging in mid-air, with no ability whatsoever to stop itself from being moved, should be easy to move. But what are the implications of such a house rule from a balance standpoint? Are we setting ourselves up for headaches?

(For context: this might seem like a corner case, but we’re playing a heavily psionics-themed campaign, and so maximizing players’ opportunities to embody the tropes of telekinesis even at low levels is important. It isn’t inconceivable that someone else in a similarly-themed campaign might have similar ideas.)

How many enemies will challenge my party of four 1st-level characters, but not result in certain death?

I was asked to DM for a one-shot with people wanting to try and learn the game. I have created a not-too-complicated world in which they can run around and interact with its inhabitants.

The problem I face is the number and strength of foes that can be encountered. How do I prepare a challenge to the players while they learn the game? I want them to be a little afraid while still having chance of saving the town/rescuing the princess or prince/find the treasure.

  • These are completely new players, there will be 4 of them.
  • They will play level 1 characters: a paladin, barbarian, rogue and sorcerer.
  • I play a separate campaign with other people but have never been a DM before.
  • We expect to play for about 4 hours – unless everyone is having fun and wants to continue, of course.
  • Based on decisions, the enemies will be either goblins or pirates. I tend to keep these enemies around the same level.
  • I would like to introduce one “boss” in the shape of a goblin chief/pirate captain.

How many enemies, based on the information above, would make for a balanced and fun game? I don’t really want everyone to bite the dust on their first game ever, but also want to keep it interesting at the same time.

Query returns different result in postgresql

I am working on one project in which I am using postgresql.

I have following values

A     B -------------- 18815   0 29187   0 29494   0 28995   0 0       0 25762   3517 29291   0 29612   0 29331   0 30004   0 

Following query I am using to get my result.

select to_char(interval '1 second'*(A+B),'HH24:MI') as resulthours  For Example - select to_char(interval '1 second'*(18815+0),'HH24:MI') as resulthours (it gives result = 05:13) 

same way I got following result for all the values from both columns A and B

Result  05:13 08:06 08:11 08:03 08:07 08:08 08:13 08:08 08:20 

total – 70:29

now the issue is, expected result should be 70.55 , but I am getting gives 70:29

Pact of the Chain, Sprite Familiar. What does it mean that a “saving throw result is 5 or lower”?

I’ve been looking into the warlocks Pact of the Chain, which states that your allowed to pick from the normal familiars as well as a select few Warlock-Only familiars, including the Sprite.

When you cast the spell, you can choose one of the normal forms for your familiar or one of the following special forms: imp, pseudodragon, quasit, or sprite.

Then invocation Investment of the Chain Master states that:

If the familiar forces a creature to make a saving throw, it uses your spell save DC.

And the Sprite has a Shortbow attack that forces a creature to make a saving throw:

Shortbow. Ranged Weapon Attack: +6 to hit, range 40/160 ft., one target. Hit: 1 piercing damage, and the target must succeed on a DC 10 Constitution saving throw or become poisoned for 1 minute. If its saving throw result is 5 or lower, the poisoned target falls unconscious for the same duration, or until it takes damage or another creature takes an action to shake it awake.

From what I gather that means that the initial save for the poison should use the players save DC? So for a lvl 7 character with 20 charisma, that would be a save of 16?

Spell save DC = 8 + your proficiency bonus + your Spellcasting modifier

However the second part of the Shortbow attack states that:

If its saving throw result is 5 or lower, the poisoned target falls unconscious for the same duration

What does "saving throw result is 5 or lower" mean? Would that be the rolled number for the save + the save modifier?

saving throw result = save dice roll + save score modifier

Or would it be the resulting rest from removing the spell save DC from the rolled total?

saving throw result = Spell save DC – (save dice roll + save score modifier)

I haven’t seen the phrase "saving throw result" referring to a number before, usually it just refers to "did the creature roll over or under the spell save DC? Yes or No."