Wolfram Mathematica

Welcome! This is the main Mathematica chat room for mathematic...
ydd
Jan 15 18:09
@Domen Thanks for the info. I was wondering where people were accessing 14.2
ydd
Jan 15 14:33
Really looking forward to the 14.2 release. I'm personally excited to try out `ArraySimplify`.

As another question I'm still a little confused; was 14.2 released early and then removed? I know this was already discussed but I didn't quite get what happened
ydd
Jul 4, 2024 20:53
Why do we have this tag when we already have calculus-and-analysis?
ydd
Jul 4, 2024 20:53
ydd
May 12, 2024 04:24
Is it appropriate to answer this question with my comment here? I feel like my answer will just be an exact copy of this answer here so I feel like my answer would add no new information to the site
ydd
Apr 18, 2024 03:04
I don't know if anyone would be interested, but are there any shortcuts here to give OP a better answer?
ydd
Apr 18, 2024 03:04
I put in an answer for this question which the OP wants to find the saddle point equations for eigenvalues of hermitean matrices. I turned it into a minimization problem but I feel like there's got to be some linear algebra thereoms regarding Hermetian matrices that could make this easier (but I never took a college level linear algebra course)...(cont'd)
ydd
Dec 7, 2023 03:36
sorry haha *github
ydd
Dec 7, 2023 03:25
@Istvan Zachar I have used ConvexOptimization with Gurobi when I had a license (from my school) but this was 2 years ago on a different laptop. I believe it involved using GurobiLink from git
ydd
Aug 23, 2023 17:56
@tush there used to be FunctionApproximations ListIntegrate[](reference.wolfram.com/language/FunctionApproximations/ref/…) but it is now obsolete. The method proposed by @kirma is the suggested method by the ListIntegrate documentation now: Integrate[Interpolation[f, InterpolationOrder -> 1][x], {x, 0, 1}]
ydd
Aug 11, 2023 19:01
    graph = Graphics3D[{Yellow, Cuboid[]}];
plot = Plot3D[Sqrt[x^2 + y^2], {x, -2, 2}, {y, -2, 2},
   PlotStyle -> Opacity[0.5, Blue], Mesh -> None];
Show[plot, graph, PlotRange -> {{-2, 2}, {-2, 2}, {0, Sqrt[8]}}]
ydd
Aug 11, 2023 19:01
I think i am not understanding what you want to do, sorry. But if I wanted to plot a Cuboid on some 3d plot I would just use Show:
ydd
Aug 11, 2023 18:34
@user10478 I'm having trouble understanding exactly what you want? Maybe post in more detail as a question? Do you know about Show? reference.wolfram.com/language/ref/Show.html
ydd
Aug 8, 2023 16:54
Same default seeding for NetInitialize
ydd
Aug 8, 2023 16:48
Yes sorry SeedRandom
ydd
Aug 8, 2023 16:44
It is probably best practice though to not assign a RandomSeed[] value though I guess? Unless you want your prng to be reproducible which I guess you would have to specify a seed
ydd
Aug 8, 2023 16:42
I am also probably just going to far with the lag all the way out to `Length[rands]-1` also. I don't really use autocorrelation tests ever so I could be doing something meaningless by going out that far in the lags. Another seed that is poor is 12345. The automatic seedings appear to do much better with the autocorrelation tests
ydd
Aug 8, 2023 16:29
    SeedRandom[1234, Method -> "ExtendedCA"];
rands = RandomReal[{0, 1}, 1000];
Tally[AutocorrelationTest[rands, #, "ShortTestConclusion"] & /@
  Range[999]]
(*{{"Do not reject",473},{"Reject",526}}*)
ydd
Aug 8, 2023 16:29
Some seeds can produce suspicious autocorrelation tests, but I am not sure how important this is and I don't really know a lot about prng testing
ydd
Jun 16, 2023 20:40
except I forgot to include definition of err in that code block err[inp_] := Abs[inp . pTab - E];
ydd
Jun 16, 2023 20:39
Haha! I did it
ydd
Jun 16, 2023 20:37
maxPower = 6;
maxInteger = 9;
pTab = Table[ Pi^-i, {i, 0, maxPower}];
soln = x /.
   QuadraticOptimization[
    Norm[Inactive[Plus][{pTab} .
       x, -{E}]], {-maxInteger \[VectorLessEqual]
      x \[VectorLessEqual] maxInteger}, x, Integers,
    Tolerance -> 10^(-20), PerformanceGoal -> "Quality"];
representation = pTab . soln
error = err[soln] // N
ydd
Jun 16, 2023 20:37
@b3m2a1 ok thanks. I will try it now as I wrote a version that uses QuadraticOptimization instead of a brute force search for finding coefficients. It is fast but does not always find the optimal values.
ydd
Jun 16, 2023 18:11
Also apparently I don't know how to format code blocks in chat... :(
ydd
Jun 16, 2023 18:10
I was inspired to do this when reading about Almost Integers and thought I would try something sort of similar. Here I wrote a small code that finds the best representation of E as a sum of inverse powers of Pi with integer coefficients. It just brute force searches over all combinations of integer coefficients in a small range. If anyone else wants to play around with it here it is:
```
maxPower = 5;
pTab = Table[ Pi^-i, {i, 0, maxPower}];
err[inp_] := Abs[inp . pTab - E];
maxInteger = 4;
tups = Tuples[Range[-maxInteger, maxInteger], maxPower + 1];
ydd
Jun 11, 2023 16:21
@MichaelE2 thanks. And yes @Nasser I have the same problem
ydd
Jun 11, 2023 04:39
Is there a better way to copy long code blocks from a question other than highlighting it with your cursor?
ydd
Jun 6, 2023 04:54
Wish I had more to say but I'm still only on question 4 so far. I wish the Q, A, and comments were all together for each number, because I am reading the answers one at a time, reading the commentary, and then I have to go back to re-read what the last question was...but I probably need to loosen up because this is just a fun read
ydd
Jun 6, 2023 04:51
@Nasser this was enjoyable to read
Jun 1, 2023 18:16
But the only thing I changed is I removed the newlines and put A and B in different cells. But now they have the frame line between them since Frame->All and I don't know how to tell Frame to put Frame lines everywhere except between the cells containing A and B
Jun 1, 2023 18:13
Grid[{
{1, SpanFromLeft, "A"},
{3, SpanFromLeft, SpanFromAbove},
{4, 5, "B"},
{6, 7, 8}
}, Frame -> All]

Is this closer to what you're looking for? I couldn't figure out how to remove the frame line however between "A" and "B". I don't know why the rows have different vertical span in your implementation
 

 Linear & Abstract algebra

For any discussion concerning linear, abstract or even element...
ydd
Dec 21, 2024 18:59
I should've mentioned this in the above comment, but in the matrices I'm looking at the constant scalars $k$, $b$ are always positive real-valued and $k > b$
ydd
Dec 21, 2024 18:44
Is there a name for matrices $A$ that satisfy $$A^T A = (k-b) I +b$$
where $I$ is the identity matrix and $k$ and $b$ are scalar constants (I.e. $k$ on the main diagonal and $b$ everywhere else)? I keep coming across them in some work I'm doing and I wanted to look more into them.

They must be closely related to orthogonal matrices since an orthogonal matrix $O$ satisifes $O^T O = I$, and maybe there's even a way to express $A$ in terms of an orthogonal matrix $O$?

I know if I multiply an orthogonal matrix $O$ elementwise by $\sqrt{k}$:
 
ydd
Oct 13, 2024 16:54
I feel like this could be a really good opportunity to pose this as a graph problem where the adjacency matrix is related to the input matrix, and find the highest weight cycle. The problem is I'm having issues figuring out what to do for the diagonal elements (I.e. you have the option of "staying" at a given vertex instead of moving to the next one)
 
ydd
Jul 18, 2023 04:49
Sorry I've been away for so long. Have you considered writing your sum function in C? And then adding the gradient descent method also in C? I think mma is just too slow to do this for high dimensional stuff. It already took 40 mins for 1000 points, and the computation time required grows like the square of the number of points.
ydd
Jul 11, 2023 13:46
It took ~40 mins. wolframcloud.com/env/1b2e1cb6-8b95-43ef-b0eb-0a16f68cf504 There are artifacts near the endpoints, but otherwise it is a good fit. My guess is that these artifacts come from the fact that I reduced the size of ns to get this to run in an appreciable amount of time. I can run it with the full sized ns=Floor[n/2] tonight to see (will take ~3hrs). I will let you know. I pasted the resulting reconstructed x, along with the y generated from the reconstructed x at the bottom so you can look at them without having to re-run the code
ydd
Jul 11, 2023 13:46
'val' is never assigned a value, it is just used as an indexing variable in xIndexed which is the variable list sent into FindRoot (xIndexed looks like {val[1],val[2],val[3],...} and then when FindRoot runs it returns a list of replacement rules {val[1]->number1,val[2]->number2,...} where {number1,number2,...} is the solution. As for adding bounds to my original gradient descent, I am not sure if I can implement this, but one thing you could do is at each step, if the step takes below 0, just clip the value to 0. I don't know if this will effect the quality of the solution however.
ydd
Jul 11, 2023 13:46
No need to implement BFGS. FindRoot works fine and returns a good solution if you specify a small lower bound that isn't exactly zero (like 10^-10) wolframcloud.com/env/dtrimas/Published/fasterGradDescent.nb Also if you use FindMinimum instead and select "QuasiNewton" method it actually uses BFGS anyways (convergence is quite a bit slower however with QuasiNewton compared to Newton). I didn't use this though because FindRoot worked fine once I changed the lower bound from 0 to 10^-10
ydd
Jul 11, 2023 13:46
It looks my method using FindRoot with constraints actually does not produce a good solution, so I may have to look at that.
ydd
Jul 11, 2023 13:46
After a little bit of reading through the documentation, I was able to get FindRoot to work with the constraint $x_j\geq0$ and I added it to the bottom of this notebook: wolframcloud.com/env/dtrimas/Published/fasterGradDescent.nb It's kind of messy the way I did it and probably can be done in a better way. I tested it with n=50 and ns=25 because it only takes 2 s to run 10 iterations with that. I am running it now with n=400 and with ns=100 to see how long it takes.
ydd
Jul 11, 2023 13:46
Ok, I made a new version with 'ns=100` instead of 200 and it is basically the same, but 4 times faster. I also realized I was calculating the sum function fp multiple times for the same input value with the way I defined grad and vec as separate functions, so this is quite a bit faster to run: wolframcloud.com/env/dtrimas/Published/fasterGradDescent.nb
ydd
Jul 11, 2023 13:46
I wrote this just in case you need it (but I'm sure you're familar with gradient descent) but this is a gradient descent algorithm for your problem, using $\frac{\pi}{4}y^{-2}$ as an initial condition. You can optimize the step size on each descent step if you like. It's not an analytical solution, so I again did not want to post this as an answer wolframcloud.com/obj/dtrimas/Published/gradDescent.nb
ydd
Jul 11, 2023 13:46
The approximation $𝑦_j \approx \frac{1-e^{-x_j}}{x_j}$ only works for large $x_j$ though
ydd
Jul 11, 2023 13:46
I didn't want to put this as answer because it's not a general solution: for large valued x, $y_j \approx \frac{1 - e^{-x_j}}{x_j}$ Solving for $x_j$ yields $x_j \approx \frac{1 + y_j \mathrm{ProductLog}[-\frac{e^\frac{-1}{y_j}}{y_j}]}{y_j}$ you can test this by multiplying x by a large value: inv[yj_] = First@SolveValues[(1 - Exp[-xj])/xj == yj, xj]; xBig = 10^6 x; yBig = Table[RT[xBig, i, ns], {i, Length@xBig}] // Quiet; xnBig = inv[yBig]; Norm[xnBig - xBig]/Norm[xBig] (about 10^-7) Ifyou plot xnBig, you'll see it captures all of the behavior of xBig
ydd
Jul 11, 2023 13:46
Just a comment on my previous comment, I actually was testing this with smaller n (n=100) and realized they aren't perfectly equal when n=400. The relative difference though Norm[time2 - fln]/Norm[fln] is on the order of $10^{-7}$ however so they are almost the same.
ydd
Jul 11, 2023 13:46
interestingly, fln is the same (up to a constant) as applying RT again to time and squaring it: time2 = Pi/4*(Table[RT[time, i, ns], {i, Length@time}]^2); Norm[time2 - fln] // Chop (*outputs 0*)
 
ydd
Jun 30, 2023 07:37
@Max which answer?
ydd
Jun 30, 2023 07:37
@MichaelE2 I got the same answer using SeriesCoefficient expanded at $z=0$ and then setting $z=-1/4$. I was hoping FindGeneratingFunction would find a non-Hypogeometric generating function for the series coefficients but it returned the original $_5F_4$ expression. Do you think there is another way to force FindGeneratingFunction to only search in the elementary function space?
ydd
Jun 30, 2023 07:37
@Max PolyLog[4, (1 - Sqrt[5])/2] + PolyLog[4, (-1 + Sqrt[5])/2] can be simplified to 1/8 PolyLog[4, 3/2 - Sqrt[5]/2] But the PolyLog Part still remains. I will see if I can express it as a product of a rational with an irrational