/r/Mathematica

Photograph via snooOG

For information and tips about Mathematica features.


related reddits:

/r/Mathematica

11,357 Subscribers

1

I'm trying to find de "a" and "b" values with this code but it's keep running the evaluation forever, so a think a did something wrong there...

V[x_] = (1 - Exp[-Sqrt[2/3]*x])^(2);

drV[x_] = D[V, x];

Solve[-drV/V == -Sqrt[2], x];

phif = 0.940;

X = (1 + (2 - a)*phi/(2 Sqrt[3 b]))^(2/(2 - a));

M[phi_] = -Sqrt[b/3] (X^a (a + 6 X) - 3 b*X)/(X^(1 + a/2)*(2 X^a - b));

drM[phi_] = D[M[phi], phi];

Mf[a_, b_] := M[phif] == V[phif];

drMf[a_, b_] := drM[phif] == drV[phif];

Solve[{Mf[a, b], drMf[a, b]}, {a, b}]

0 Comments
2024/11/21
00:16 UTC

2

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

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

0 Comments
2024/11/20
09:34 UTC

0

Finding count of the number of words beginning with "q"

Here is the code generated taking help of an AI tool (ChatGPT):

Count[WordList[], StringMatchQ[#, "q" ~~ ___] &]

https://preview.redd.it/j34g0ev3qm1e1.png?width=1024&format=png&auto=webp&s=0c138d5a083da79d1e4e3093d0340866d340a00b

There is definitely something wrong as the output should not be zero.

The syntax StringMatchQ[#, "q" ~~ ___] & is something I find difficult to relate. It will help if someone could explain the relevance of #, ~~ ___, & within the code. Of course since the code is apparently giving wrong output, first need to revive the correct code.

Thanks in advance!

9 Comments
2024/11/18
09:38 UTC

0

Understanding TextSentences function

https://preview.redd.it/i4jxkeibbl1e1.png?width=1024&format=png&auto=webp&s=ad0395d4725d688de2a1f6acdef2ca38fc7f9c42

https://preview.redd.it/y7rwp18gbl1e1.jpg?width=1920&format=pjpg&auto=webp&s=0c798fe4e88212b0853f2dc6a483ca7e4fe7c92e

On running TextSentences[x], it will help if anyone can explain how the Wolfram Languages infers for example "Resrly" is not the first word of a new sentence.

1 Comment
2024/11/18
04:49 UTC

0

Reason output showing in list form

https://preview.redd.it/6f7t43588g1e1.png?width=1024&format=png&auto=webp&s=55abe4cad0adb8fa5cd853d2a4e039a8e3e12bf6

StringLength[MaximalBy[WordList[],StringLength]] 

Not sure why the output is in list form. Obviously there should be a way to convert this list form into integer form.

1 Comment
2024/11/17
11:42 UTC

0

Showing in the form of a string first letter of sentences

The problem is to make a string from the first letters of all the sentences in the Wikipedia article about computers.

Here is my tentative code:

StringJoin[StringTake[StringSplit[WikipediaData["computers"],"."], 2]] 

https://preview.redd.it/fs0r1jrkge1e1.png?width=1024&format=png&auto=webp&s=54954a1a8b005db37fa1b152241a15ab1631531e

Not sure about the error messages shown in red above.

I chose 2 instead of 1 for StringTake argument as there seems to be a whitespace after period.

Help is sought also for how to ensure that the first letter after a sentence is selected irrespective of it appears after the period or followed by one or more whitespaces.

5 Comments
2024/11/17
05:45 UTC

0

Understanding double square bracket [[1]] for extracting portion of a list

StringSplit[stringsample,{"."}][[ 1]] 

The double square bracket syntax appears not that intuitive with otherwise the usual way which is putting one function above the other.

If I understand correctly, the output of StringSplit function which is a list is being used by [[1]] to show just the first element of the list. What appears strange is the syntax.

1 Comment
2024/11/16
11:17 UTC

1

Using StringSplit and show output within quotes

https://preview.redd.it/zn5kg68rc51e1.png?width=1024&format=png&auto=webp&s=715ef9d25b17651c6026b168b79050c8d3190378

The goal is to by using StringSplit, split the text on the basis of comma appearance.

StringSplit["Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",","] 

The above syntax generated after referring to Wolfram docs on StringSplit:

https://preview.redd.it/iyzn5rddd51e1.png?width=1024&format=png&auto=webp&s=8f2ab1c3623abedea34c05a12a12112894db7d21

It seems the comma is indeed split but difficult to discern from the output. So trying to take help of InputForm function in order to show each substring with quotes.

https://preview.redd.it/4hch1elje51e1.png?width=1024&format=png&auto=webp&s=4495bf4c692b5eca24e6bd08ff8088809473929d

The docs uses InputForm[%] as second code after the StringSplit code. Not sure how the second code using InputForm function will know that it is the previous code of which referred.

I tried to do the same with my code and here is the screenshot:

https://preview.redd.it/084qubpze51e1.png?width=1024&format=png&auto=webp&s=920097c6381965c9895f42113cbec96cd8eefd58

3 Comments
2024/11/15
23:20 UTC

2

Choose a product to launch

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.

https://preview.redd.it/nr2rnglhix0e1.png?width=1330&format=png&auto=webp&s=b82f0119e8bb618f702a8b0b95f0c6dc69a451c8

0 Comments
2024/11/14
20:44 UTC

0

Find the string positions where the periods occur in the article

https://preview.redd.it/ex4bakm1su0e1.png?width=1024&format=png&auto=webp&s=744ef83aefb3440d06880f109ad9cbf99f754ec1

StringPosition[WikipediaData["Strings"],"."] 

The aim is to find the positions where the periods occur in the article. The output is strange with only 3 results.

1 Comment
2024/11/14
11:35 UTC

0

Counting of number of words in a string with StringSplit and Length

https://preview.redd.it/5kkdpmeuvs0e1.png?width=1024&format=png&auto=webp&s=5b5bf1529db293a95f3a56c95d713e5647733d04

For finding how many words are there in the Wikipedia article "Computer", after running the below code, getting 9358 (instead of 9239):

https://preview.redd.it/jmwllyp79u0e1.png?width=1024&format=png&auto=webp&s=908a5f031b3582d43568510c6af861bcd0115dd3

https://preview.redd.it/w1so87u79u0e1.png?width=1024&format=png&auto=webp&s=2961f0e7af17a949b0d18f19cec0f38084af4ae8

Length[StringSplit[WikipediaData["computer"]]] 

If I am correct, StringSplit counts each word based on the number of times it encounters white space while parsing through the whole string. So even if there are punctuation marks like commas, that should not affect the count of words.

0 Comments
2024/11/14
05:17 UTC

0

Find the string length of the Wikipedia article for "computer'

This is a question in exercises part of Strings & Text (An Elementary Introduction to the Wolfram Language).

Not sure what it means by Wikipedia and 'computer' in this context. Is WikipediaData function designed so as to access the content of wikipedia.org?

Also what it exactly means by Wikipedia article for 'coimputer'. Will it refer to this url page: https://en.wikipedia.org/wiki/Computer?

1 Comment
2024/11/14
00:43 UTC

1

Why bar chart starts on the x axis leaving a gap in the first unit

https://preview.redd.it/kfb6qlkkum0e1.png?width=1024&format=png&auto=webp&s=045dce4fa348ff2ba97deaabc130de084a7ca10d

BarChart[StringLength[StringSplit["A long time ago, in a galaxy far,far away", ","]]] 

While I can follow the reason for three bars as there are 2 commas in the string, unable to grasp the reason why first unit in the x axis left empty (or with zero value).

1 Comment
2024/11/13
08:54 UTC

1

Beginner needs help solving implicit equation

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]

{}

https://preview.redd.it/r0f2uqrcxb0e1.png?width=904&format=png&auto=webp&s=e002d1fde5e5b0529d4d6eb5dab4c06d959e4ab8

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

2 Comments
2024/11/11
20:09 UTC

3

Laptop specs for Mathematica

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!

9 Comments
2024/11/11
14:45 UTC

0

Fubini theorem

Hello, I'm going to present a Calculus 2 seminar on Fubini's Theorem and I need to solve contextualized situations in the area of ​​Engineering that involve this topic. Could anyone help me with 3 practical examples, applied to Engineering, using Fubini's Theorem, with detailed resolution? Thank you very much for the help!

1 Comment
2024/11/10
16:42 UTC

2

Defining list mentioning other function as part of output not allowed?

https://preview.redd.it/i0xtfz24f20e1.png?width=1024&format=png&auto=webp&s=da13899ff9b9317399f14b1ca7bd834bc0b3beab

f[x_Integer] := x + 108 
h[x_Integer] :=x + 77

SetAttributes[f, Listable] 
f[x_List] := h/@x 
f[{44,444}] 

 Given I have referred h function here: f[x_List] := h/@x , I expected the output of f[{44,444}]  to be 121 (77 + 44) and 521 (77 + 444). So my query is how even after inclusion of h, the output of list still referring to f. Is it then wrong to code:

f[x_List] := h/@x 

And what is the implication or utility of mentioning h (as part h/@x) when anyway it will be g/@x.

3 Comments
2024/11/10
12:20 UTC

1

Map and Prefix: Relevance of prefix when the function is listable by default

Continuing with my earlier post Difference between prefix and map and why they produce the same output in this code, it will hep if someone can clarify the difference between these 3 codes giving the same output:

https://preview.redd.it/fioimzv5e00e1.png?width=1024&format=png&auto=webp&s=94669268efc9ce1e3ee4fc0c9a689e2c6d67b6ba

The first one is the most intuitive and this is the way till now I have been using functions most of the time:

StringLength[StringSplit["A long time ago, in a galaxy far, far away", {",", " "}]] 

If I understand correctly, the second one and third ones are giving the same output as StringLength function has listable attribute added by default.

StringLength@StringSplit["A long time ago, in a galaxy far, far away", {",", " "}] 

StringLength/@StringSplit["A long time ago, in a galaxy far, far away", {",", " "}] 

If listable attribute were not added by default to the StringLength function, then mapping was needed (by using /@).

This now brings the need to use prefix (by using @) when even without the use of prefix, there is the same output as in the first code.

2 Comments
2024/11/10
05:29 UTC

0

Difference between prefix and map and why they produce the same output in this code

Running the two operations produces same result for these codes:

StringLength /@ StringSplit["A long time ago, in a galaxy far, far away", {",", " "}]
    
    Output:
    
        {1,4,4,3,0,2,1,6,3,0,3,4} 

StringLength@StringSplit["A long time ago, in a galaxy far, far away", {",", " "}] 

    Output:
        {1,4,4,3,0,2,1,6,3,0,3,4} 

On further check, it appears first one performs map operation while the second one is called prefiix. Both are meant to do different things apparently.

3 Comments
2024/11/09
16:52 UTC

1

pls help

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

1 Comment
2024/11/09
09:55 UTC

0

Correct usage of StringSplit that takes into account adjusting comma

BarChart[StringLength[StringSplit["A long time ago, in a galaxy far,far away"]]] 

https://preview.redd.it/k063k9vhptzd1.png?width=1024&format=png&auto=webp&s=bc1ed48dc5e6c205d491c4c1e8f8926e8ba5d6fc

The above code seems counting ago, as a word of length 4 instead of 3 due to comma.

Requesting help for correct usage of StringSplit function that takes into account adjusting comma (or other punctuations).

5 Comments
2024/11/09
06:53 UTC

0

What is wrong with this ImageAdd and Negate function

ImageAdd[
    Negate[EdgeDetect[Import["https://wolfr.am/EIWL-SW-Image"]]], 
    Import["https://wolfr.am/EIWL-SW-Image"]
]

https://preview.redd.it/itdlaw68omzd1.png?width=1024&format=png&auto=webp&s=5f0258f3205d54edbabb602c2c16dbb2cb532db2

4 Comments
2024/11/08
07:13 UTC

1

Looking for specific Graph Automorphism?

I have a family of graphs, and I only need to see that an automorphism exists which contains a specific single vertex mapping, for example [1->96], to see that the entire graph is vertex-transitive. Is there a way to restrict the search based on this? I’ve tried somethings but nothing has run faster than just checking with VertexTransitiveGraphQ.

4 Comments
2024/11/07
23:59 UTC

2

Help making an efficient pdf graphic

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.

8 Comments
2024/11/05
04:03 UTC

1

Any help with clueless mathematica user?

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]

4 Comments
2024/11/04
21:00 UTC

2

Mathematica Font

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?

0 Comments
2024/11/04
09:09 UTC

1

CTRL command taking me to nearest subsection while using Text cells

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.

0 Comments
2024/11/04
04:15 UTC

0

Pure function with and without mapping

https://preview.redd.it/7fzurjdmhnyd1.png?width=1024&format=png&auto=webp&s=060413da88b13c29293836f7dcc59dcf5b1f963e

#^2&[{1,2,3,4,5}] 

#^2& /@{1,2,3,4,5} 

I understand a similar problem can be solved in many ways in Wolfram.

If I interpret correctly first one is an example without using mapping. The syntax here is to use square bracket and then curly braces for list.

In the second example with mapping /@, no need to use square bracket and curly brace as part of list ensures each element of the list iterated.

1 Comment
2024/11/03
08:58 UTC

3

Understanding label syntax with this Manipulate code

Without label, this is the code:
 

Manipulate[
  ColorData["Rainbow"][#] & /@ Rescale[Range[1, n], {1, n}, {0, 1}],
  {n, 5, 50, 1}
]

https://preview.redd.it/9mfwb84f2myd1.png?width=1024&format=png&auto=webp&s=c33208a5fefee7f69348f961461263a46f6db9b2

With label in slider:

Manipulate[
  ColorData["Rainbow"][#] & /@ Rescale[Range[1, n], {1, n}, {0, 1}],
  {{n, 5, "Number of Hues"}, 5, 50, 1}
]

It is difficult for me to figure out this part:

{n, 5, "Number of Hues"}

5 is the beginning of the slider which is already mentioned as 5, 50, 1. So why 5 is once again placed within {n, 5, "Number of Hues"}.

2 Comments
2024/11/03
04:12 UTC

1

CompetifyHub November POTM

Competify Hub provides high quality problems monthly for the reddit server, we will provide the solution in the next month's post.

October POTM Solution: 65/8. Let H and O be the orthocenter and circumcenter of ∆ABC, respectively. Since H is one of the foci, O must be the other focus because H and O are isogonal conjugates. Now, let H’ be the reflection of H over BC. It is well-known that H’ lies on the circumcircle of ∆ABC, so the length of the major axis is OH’ = (13)(14)(15)/(4[ABC]). The semiperimeter of ∆ABC is (13 + 14 + 15)/2 = 42/2 = 21, so by Heron’s Formula, we get [ABC] = √(21 * (21 - 13) * (21 - 14) * (21 - 15)) = √(21 * 8 * 7 * 6) = 84. Thus, the length of the major axis is (13)(14)(15)/(4 * 84) = 65/8.

November POTM If A is a point on the graph of y = x^2 and B is a point on the graph of y = 2x - 5, find the minimum possible distance from A to B. Express your answer as a common fraction in simplest radical form.

If you are interested in discussing about math in general, free math competition resources or competing in international competitions check out our website (https://competifyhub.com/) or discord server here: https://discord.gg/UAMTuU9d8Z

1 Comment
2024/11/03
01:37 UTC

Back To Top