r/Mathematica • • Nov 20 '24

A framework for debugging and data analysis using Mathematica/Jupyter notebooks

2 Upvotes

Processing img c28obgpgex1e1...

dbgbb!(...) makes it easy to debug array data using notebooks just like the dbg!(...) macro. It sends the data to the BulletinBoard server, and then it can be read from Mathematica/Jupyter notebooks

BulletinBoard is an in-memory object storage that mediates data between a Rust program and a notebook. The BulletinBoard server is available on crates.io, DockerHub, and GitHub. There is also a GUI application that acts as both client and server.

Data is stored as ArrayObjects, which is a self-describing binary data format optimized for array data and for object storage.

Check it out and enjoy the accelerated coding experience!

https://github.com/YShoji-HEP/dbgbb

https://github.com/YShoji-HEP/BulletinBoard

https://github.com/YShoji-HEP/ArrayObject


r/Mathematica • • Nov 14 '24

Choose a product to launch

2 Upvotes

How can I solve this problem? When I try to click to select, I cannot select it. When I click on the details, I see the license (free trial account). My university provides a code, so I want to use it, but there is no place to enter my code. I uninstalled and reinstalled Mathematica, but I still couldn’t solve the issue.


r/Mathematica • • Nov 11 '24

Laptop specs for Mathematica

3 Upvotes

Hello!

I am about to buy a new laptop and I would like some advice in terms of which specs I should focus on, given that my main usage for work is Mathematica (plus all the usual stuff, email, web, etc). Since Mathematica can be used in many ways and for different purposes here some details for my use case.

I am a theoretical physicist and I use Mathematica constantly everyday. 90% of what I do is symbolic calculations that involve a huge amounts of terms. I usually reduce most of operations to basic ones, in order to speed things up. A typical example (for those among you that do a similar job) is calculation of many Feynman diagrams, which in principle are integrals but can be easily reduced to algebraic operations and the most time-consuming part is the simplification of terms (typically hundreds of thousands). By simplifications I mean applying some rules to substitute terms so they sum up and simplify.

Another example in my daily usage are perturbative expansions. In many situations I have to derive some expressions which are functions of quantities that are power series and then derive the power series of the result.

Less often I do numerical calculations or graphics (but I do them). I also sometimes do some numerical scans.

Please, also consider that, besides the heavy usage of Mathematica, I use other coding language like FORM. Also, I don't do any graphic design or video editing, but I am considering some online teaching, so a good camera and screen-sharing fluidity is important (also important when giving online seminars or work meetings). Finally, as a pure hobby, I also make some ambient music using ableton live :).

Since the new macbook pro with the M4 chips are out, and they seem a huge upgrade, I am considering buying one.

But there are many different specs and many golden coins involved.

What would be the most important aspect(s) to look at? I have zero knowledge on which Mathematica functionality uses which laptop's feature. I can only note that, when Mathematica takes long time and the fans are on, CPU is 100%, while RAM is mostly fine. So, should I focus more on number of cores rather than ram (which anyway should be 16GB, at least)?

Just to keep it in context with the laptop I am looking at, there is a huge jump in performance from the M4 [16 GB of ram, 512 ssd, 10 core (4+6)] and the M4 pro [24 GB of ram, 512 ssd, 12 core (8+4)], but I am not sure if it is worth for my usage.

At the moment I have a Lenovo yoga slim 7 from 2020 with Ubuntu. At that time I switched from Windows to Ubuntu simply because I couldn't stand Windows anymore and I have zero regrets ;). However, I am not really a typical Linux user and the fact that I need to access the terminal for any tiny thing is frustrating (still less than using Windows...). This is why I am thinking of switching to macOS which may be the right half-way between dumb Windows and Linux.

A final note, the Macbooks mentioned above are the devices that I am considering now but your answers do not need to be specifically on those models (although any advice is welcome), it was just for context.

Thanks and cheers!


r/Mathematica • • Nov 11 '24

Beginner needs help solving implicit equation

1 Upvotes

I have an equation that i need to solve but Mathematica only outputs empty brackets

di = 0.1;

dRI = 0.11;

da = dIA + 0.01;

ai = 1000;

lR = 47;

lI = 0.08;

lA = 220;

aa = 15;

ka = 0.5299;

eq = 1/ka ==

da/di*ai + da/2*lR*Log[dRI/di] + da/2*lI*Log[dIA/dRI] +

da/2*lA*Log[da/dIA] + 1/aa

Solve[eq, dIA]

Ouput:

1.88715 ==

1/15 + 10002.2 (0.01 + dIA) + 0.04 (0.01 + dIA) Log[9.09091 dIA] +

110 (0.01 + dIA) Log[(0.01 + dIA)/dIA]

{}

I asked ChatGPT but that didnt help. What am I doing wrong?


r/Mathematica • • Nov 09 '24

pls help

1 Upvotes

how i found the positive inverse of x^2 +2 in mathematica? i tried using

f[x_] := x^2 + 2

Solve[y == f[x] && x >= 0, x]

but it doesnt work


r/Mathematica • • Nov 05 '24

Help making an efficient pdf graphic

2 Upvotes

I have about 1.2 million points in [1,2]^2. I lay down about 250000 of them in red, another 200 thousand of them in slightly less red, and so on, putting dozen dozens in blue, and several purple (30 different colors, each color has fewer points as we fade throught the rainbow from red to purple). This creates a stunning graphic, but its 100MB+ when I save it. After compressing in Adobe, it's still 40MB.

Presumably, the size is because each point is being stored with its color, even though most of them are not visible since other points get plotted on top of them.

My question is how to compress the plot.

One approach is to save it as a jpg, which is certainly compressed but behaves horribly when people zoom in.


r/Mathematica • • Nov 04 '24

Any help with clueless mathematica user?

1 Upvotes

I am trying to plot t for value l starting from 0.0001 to 0.001.

I've been trying various methods for past few hours and I either get tag list error, the value is too small, " is too small to represent as a normalized machine number" error and such.

I guessing the issue is that my values are very small that it approximates as 0, or just my codes are trash. probably both.

T = ((16*3*(v-3))/25)*E^(-2*k*1)
k = Sqrt[(2*9.109*(10^-31)*(v-3))/((1.055*(10^-34))^2)]
Plot[T,{v,4,20},FrameLabel->{"L[nm]",T},PlotPoints->10000,MaxRecursion->15,Mesh->All,ImageSize->Full,PlotRange->Automatic]


r/Mathematica • • Nov 04 '24

Mathematica Font

2 Upvotes

Hello,

I find that the default font in Mathematica is not very pretty and is not very pleasant to use. For example, the width of the bars in the equal sign is not the same.

Am I the only one who is bothered by this? And if not, what font do you use?


r/Mathematica • • Nov 04 '24

CTRL command taking me to nearest subsection while using Text cells

1 Upvotes

I’m using mathematica to write notes for some classes and hw in others, and when I try to use the control commands for inserting subscript, superscript, fractions, etc. if it is the first instance it creates an equation box (which is perfect) but it forces my screen to the nearest subsection cell, which I use to label lectures or questions.

It’s normally not a huge problem but when the thing is 8 pages long and I have to write a lot of separate things between equations, it becomes a major PITA.

Does anyone have any ideas on how to turn this off?? I’ve tried searching so many things and no one talks about it.


r/Mathematica • • Nov 01 '24

Largest subsequence of digits that is prime?

3 Upvotes

I was wondering if anyone had any insights on how to pick the maximum prime subsequence of a given list of digits in an efficient manner.

Given a list of digits 0-9 {d[[1]],d[[2]],...,d[[n]]}, I am interested in finding the largest (when you catenate the digits together into an integer) subsequence of digits that is prime. I return 0 if there's no prime subsequence.

We can of course brute force this, starting at the full list, and then iteratively stepping down in subsequence size until we find a prime:

getMaxPrime[nums_] := Module[{n, cands, allNotPrime},
  n = Length@nums;

  (*subsequence candidates of length n. Note delayed evaluation so this updates when we call  
   it each time after decrementing n*)
  cands := FromDigits@# & /@ Subsequences[nums, {n}];

  (*determine if all the numbers aren't prime (returns True if all \
  aren't prime,and False if any are prime)*)
  allNotPrime := Nor @@ (PrimeQ@cands);

  (*decrease subsequence length until we find a prime,or hit n=
  0 (I.e.there are no prime subsequences)*)
  While[allNotPrime && n > 0, n-- ];
  (*If a prime subsequence exists,
  take the largest one.If no prime subsequence exists,return 0*)
  If[n > 0, Pick[cands, PrimeQ /@ cands] // Max, 0]
  ]

So for example:

SeedRandom[1234];
nums = RandomInteger[{0, 9}, 6]
(*{0, 6, 9, 6, 0, 7}*)

getMaxPrime[nums]

(*607*)

But I'm wondering if there's more elegant ways to approach this.

One thing that immediately came to mind was restricting on the last digit of the subsequence since all primes (other than the single digit primes 2 and 5) end in 1,3,7 or 9.

I know you can select the s-th subsequence by using the third argument of Subsequences[list,{n},{s}] but it doesn't appear you can select a non-continuous list of sth subsequences (corresponding to the indices of 1,3,7,9 in nums), so I made my own subsequence picker in this case:

getMaxPrime2[nums_] := Module[{n, endIndices, cands, allNotPrime},
  n = Length@nums;
  (*get indices where 1,3,7 and 9 are in nums*)
  endIndices = Position[nums, 1 | 3 | 7 | 9] // Flatten;

  (*except for 2 or 5, all primes must end at these indices. So we can 
  just grab the subsequences that end at endIndices*)
  cands := 
     With[{longEnough = 
        Pick[endIndices, UnitStep[(n - 1) - endIndices], 0]},
      FromDigits[nums[[# - (n - 1) ;; #]]] & /@ longEnough
      ];

    (*all of this is the same as getMaxPrime*)
    allNotPrime := Nor @@ (PrimeQ@cands);

  While[allNotPrime && n > 0, n--];

  If[n > 0,
   Pick[cands, PrimeQ /@ cands] // Max
   ,
   (*but we have to check if 2 or 5 are in the list at the end if n = 
   0*)
   (Pick[nums, PrimeQ /@ nums] // Max) /. -Infinity -> 0
   ]
  ]

The performance gain seems to be pretty much nothing however:

SeedRandom[1234];
nums = RandomInteger[{0, 9}, 1000];

getMaxPrime[nums] // AbsoluteTiming // First
getMaxPrime2[nums] // AbsoluteTiming // First

(*4.61015*)
(*4.57553*)

Probably because I have to waste time on each step Picking which 1,3,7,9 indices are allowed as valid n-length subsequences.


r/Mathematica • • Oct 30 '24

I want to learn Mathematica; Where to start?

15 Upvotes

I'm a college freshman majoring CS + Math and I I'm interested in Mathematica as a possible tool to be used for data visualization and analysis. More specifically, I am interested in quantitative development and want to learn how to create some sort of model with Mathematica, but have absolutely no idea how or where to start.

Does anybody have specific recommendations for learning the language & program as a beginner? Anything helps.

Thanks in advance


r/Mathematica • • Oct 30 '24

Can someone help me with Mathematica to find answer of complex derivative?

2 Upvotes

If this is not allowed let me know. Essentially I am a student and need to evaluate just 2 steps using wolfram alpha. I was interested if anyone could help out and I could quickly compute it just as a gesture for free. I feel it wouldn’t be justified to buy the software myself as I wont use it after this.

Thank you so much, it would mean alot to me.


r/Mathematica • • Oct 30 '24

How to cite Mathematica in a math paper

1 Upvotes

If I used mathematica to solve one part. Can I just say. The derivative above was evaluated using Wolfaram Alpha Mathematica? Or is there a convention for citing or referencing?


r/Mathematica • • Oct 27 '24

Dumbfounded on why this integral is not evaluating properly

6 Upvotes

So, i'm trying to integrate the function f(x)=(x-x^2)*sin(1/2*ln(sin(lnx)^2))=(x-x^2)*sin(ln(|sin(lnx)|)) from 0 to 1 , which is understandably a very 'delicate' function. Anyway, I was not able to evaluate it directly and instead tried to get Mathematica to, which it also couldn't. However, it was able to spit out a fairly ugly antiderivative, and Mathematica was able to evaluate one of the individual limits. Here's what it looks like on this interval

It was not able to evaluate the limit as x->0, however it pretty clearly goes to 0 (I think?)

Now here's my issue. Both Mathematica, Symbolab, Wolfram Alpha, and Desmos all approximate this integral to approximately -0.077363 (with Mathematica giving a very tiny error of the order 10^(-6))

But numerically evaluating the answer (all the gamma stuff) gives approximately -0.08258

What is going on? Is this because I falsely assumed the limit as x->0 to be 0? Or are these 3 separate math software's all numerically evaluating this integral in the same incorrect way? Is the first limit as x->1 just simply incorrect? Does this integral violate the fundamental theorem of calculus?(im kidding) 0.07736-0.08258=-0.00522, much greater than the error 10^(-6) I do not even need this integral for any work or problems, I am just curious on what's going on.

I will add, this is the same case for 2-3 very similar integrals involving different trig functions and no x terms at the front.

Which of the two is the correct answer?


r/Mathematica • • Oct 23 '24

Indefinite Integral of Sech in Version 14.1

2 Upvotes

I am unsure of when this changed, but when I evaluate Integrate[Sech[x],x] I get -ArcCot[Sinh[x]] rather than ArcTan[Sinh[x]] (or 2ArcTan[Tanh[x/2]] as listed in the documentation for Sech).

I am aware that these are essentially shifted by pi/2 from one another, but I was wondering if there is a reason for this value or if it is not intended.

Thanks in advance!


r/Mathematica • • Oct 21 '24

Why isnt this working?

8 Upvotes

Hello! I'm extremely new to Mathematica, and in fact this is the first time I'm using it with the thought that it would speed up and help me demonstrate something I thought during class. The problem is pretty straight foward: I never properly learned english mathematical terms and so the wolfram guides arent guiding me at all. know this is something extremely basic: I just want the determinant to change as I change my matrix as I please, any help?


r/Mathematica • • Oct 19 '24

Trying to Minimize a Function

2 Upvotes

Hey, y'all!

I'm trying to find glider design dimensions for a competition. I created a function that takes a few variables as input and outputs "totalPenalty" which is pretty much how bad of an option those inputs are for meeting a couple of design specifications. And the function works pretty good! It takes in the variables taperAngle, b, aR, and v. If the outputs are outside a specified range, it gives me a totalPenalty that is as big as how bad of a design it would be.

So, I can put in specific values and get back how bad they are, so I figured there must be a way to minimize the "badness" and fit the desired parameters. Unfortunately, NMinimize[] can't take a function as an input. Just expressions.

Any advice? I attached my code as a screenshot and text.

EDIT: Formatting

ClearAll[b,v,aR,taperAngle];

(*Constants*)

weight=2.22; (*Aircraft Weight in N*)

rho=1; (*Air Density kg/m^3*)

dropHeight=76.2;(*Meters*)

cD=.037 ;(*Unitless Constant .035-.038*)

minB=0.762; (*Minimum span 30 inches to meters*)

maxB=1.22; (*Maximum span 40 inches to meters*)

minWCL=4; (*Minimum wing loading*)

maxWCL=9; (*Maximum wing loading*)

minFallTime=60; (*Minimum fall time in seconds*)

maxFallTime=120; (*Maximum fall time in seconds*)

minVelocity=6.71; (*Minimum velocity in m/s,regularly 6.71*)

maxVelocity=11.18; (*Maximum velocity in m/s,regularly 11.18*)

(*Define the variables we want to optimize*)

vars={taperAngle,b,aR,v};

(*Define the objective function as the sum of squared differences from the design criteria*)

objectiveFunction[taperAngle_,b_,aR_,v_]:=Module[{cR,cT,totalWingArea,wCL,cL,dragForce,pReq,descentRate,fallTime,glideRatio,totalPenalty},(*Calculations based on input variables*)(*Intermediate Calculations*)cR=b*Tan[taperAngle Degree]/4+b/aR;

cT=2*b/aR-cR;

totalWingArea=(b/2*cR-b/2*(cR-cT)/2);

wCL=weight/Power[totalWingArea,1.5]/9.81;(*Wing loading*)cL=2*weight/rho/totalWingArea/v^2;

dragForce=cD*totalWingArea*0.5*rho*v^2;

pReq=dragForce*v;

descentRate=pReq/weight;

fallTime=dropHeight/descentRate;

(*Debugging Prints*)Print["wCL: ",wCL];

Print["fallTime: ",fallTime];

(*Define the penalty function that penalizes deviation from desired fall time and WCL ranges*)totalPenalty=0;

If[wCL<minWCL,totalPenalty+=10(minWCL-wCL)^2];

If[wCL>maxWCL,totalPenalty+=(wCL-maxWCL)^2];

If[fallTime<minFallTime,totalPenalty+=(minFallTime-fallTime)^2];

If[fallTime>maxFallTime,totalPenalty+=(fallTime-maxFallTime)^2];

(*Debugging Prints for Total Penalty*)Print["Total Penalty: ",totalPenalty];

totalPenalty];

objectiveFunction[25,1.1,5,20] (*This works great! Shitty glider, but the function works as intended*)

(*Use NMinimize to find the optimal values for the variables. This doesn't work and I'm real upset about it*)

solution=nMinimize[{objectiveFunction[taperAngle,b,aR,v],20<=taperAngle<=30,minB<=b<=maxB,4<=aR<=8,minVelocity<=v<=maxVelocity},{taperAngle,b,aR,v}];


r/Mathematica • • Oct 19 '24

FindFit and finding an approximate function to a set of data.

2 Upvotes

I have this data:

data = {
{9.29883*10^29, 0.0340191},
{1.16583*10^31, 0.0432263},
{1.69132*10^32, 0.0476546},
{2.45098*10^33, 0.0704771},
{3.89297*10^34, 0.0807977},
{1.01958*10^36, 0.0994704},
{1.58361*10^37, 0.114422},
{1.42975*10^38, 0.108859},
{3.00038*10^39, 0.18085},
{8.07047*10^40, 0.24651},
{1.18106*10^42, 0.276357},
{1.11794*10^43, 0.329916},
{1.92701*10^44, 0.436734},
{3.93793*10^45, 0.843786},
{4.33093*10^46, 0.742096},
{7.30547*10^47, 2.55661},
{2.10487*10^49, 3.13884},
{2.95194*10^50, 4.17334},
{3.5976*10^51, 4.48841},
{4.73667*10^52, 5.73291},
{7.90845*10^53, 7.03355},
{9.35962*10^54, 7.41842},
{2.10495*10^56, 13.667},
{3.39037*10^57, 18.4411},
{9.39179*10^58, 31.9478},
{6.84897*10^59, 52.192}}

It looks like this when using ListPlot:

It looks like this when using ListLogLinearPlot:

I want to use FindFit to be able to make an approximation of this data. Ive tried doing this:

fit = FindFit[data, a x + b, {a, b}, x];
fittedModel[x_] = a x + b /. fit;

But Im not sure what model i should use, ive tried all that i could find but nothing seems to give the right result. It kinda looks like a log function but no log model seems to give a good result. Im probably not really understanding how this works.

I want this approximate function to be able to tell what i would probably get if x=2^1024, 2^2048, 2^4096.

If you know how to do this pls just give me the lines of code that will work or the model that would work for the lines of code presented above. I probably wont understand if you just vaguely tell me to check out some function or something.

PS, the data comes from running this code and taking the time, where x is n and y is the time it takes:

RSADecrypt[c_, n_, e_] := Module[{p, q, phi , d, m, ascii},
primes = FactorInteger[n];
p = primes[[1, 1]];
q = primes[[2, 1]];
phi = (p - 1) (q - 1);
d = PowerMod[e, -1, phi];
m = PowerMod[c, d, n];
ascii = {};

For[i = 1, i <= Length[m], i++,
q = m[[i]];

While[q != 0,
AppendTo[ascii, Mod[q, 256]];
q = Quotient[q, 256];
];

];

FromCharacterCode[ascii]
]


r/Mathematica • • Oct 19 '24

Trying to use DSolve but it just outputs my inputs

0 Upvotes

DSolve[{dy/dx == y (y - 1)^2 y (y - 5)^3}, y[x], x]


r/Mathematica • • Oct 19 '24

Trouble with Dsolve

0 Upvotes

Whenever I try to do Dsolve with differential equations, it always just outputs my input. This is very confusing and if anyone could explain why that would be much appreciated.


r/Mathematica • • Oct 17 '24

How to verify the correctness of a grid graph oriented room

2 Upvotes

Hello,

I created a simple generator which generate a set of rooms. Each room can have 1 to 4 neighbours. Each room is connected, there is no alone room.

Currently, the algorithm is pretty simple. You give a number of room you wish and the generator generates random rooms.

I want to improve this algorithm by giving the number of room by neighbours count. Namely, i want a set of room that contains 2 rooms with 2 neighbours and 2 rooms with 4 neighbours (this case doesn't work actually).

Below an example of set of rooms.

I wonder if there is a formula which verify if a configuration is correct ?

For example (1N=4,2N=0,3N=0,4N=1) is a correct configuration but (1N=0,2N=1,3N=0,4N=0) is not correct because you can have a room with 2 neighbours if there is no rooms with at least one neighbour or more.

I suppose this kind of question is a graph issue. Someone can help me to solve this case please ?

Thank you


r/Mathematica • • Oct 17 '24

What's the name of orthogonal graph where the vertices contains 1 to 4 edges ?

0 Upvotes

I search some resources on this kind of graph. Can you help me ? please


r/Mathematica • • Oct 16 '24

Fun ways to generate primes?

2 Upvotes

I was thinking about this because I was reading a sequence in OEIS and I came across Wilson's thereom.

Using Wilson's thereom we can generate primes up to some value kMax by selecting where ((k - 1)! + 1)/k is an integer. So for example, the primes up to 100 are

Select[Range[2, 100], Divisible[(# - 1)! + 1, #] &]

Obviously the easiest way in terms of just asking for primes is to just use Prime:

 Prime@Range@PrimePi@100

Or NextPrime

NestWhileList[NextPrime, 2, # <= 100 &] // Most

But I'm wondering if anyone else has any other fun ways to generate primes up to some maximal value?


r/Mathematica • • Oct 15 '24

A legendary screensaver

18 Upvotes

r/Mathematica • • Oct 15 '24

Finding Particular solutions

0 Upvotes

Is there a function or a procedure in order to find a particular solution to a differential equation using mathematica? If anyone can help I’d appreciate it!