/r/Mathematica

Photograph via snooOG

For information and tips about Mathematica features.


related reddits:

/r/Mathematica

11,259 Subscribers

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

3

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

0

Hue function in Wolfram with one and three parameters: Are they interchangeable?

Hue[0.4,0.7,0.6] 

Hue[1] 

As per my understanding since the color space is same, Hue function derived with one parameter can be replaced with a unique value of a Hue function with three parameters.

https://preview.redd.it/6tc35huz5hyd1.png?width=1024&format=png&auto=webp&s=f016f5c23adf756f7a7e972e18d8bc2651a0e5bf

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

It will help if anyone can confirm and if indeed replaceable, which command or code to replace.

3 Comments
2024/11/02
11:35 UTC

3

Largest subsequence of digits that is prime?

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.

2 Comments
2024/11/01
22:56 UTC

1

Adding multiple sliders for this Manipulate function with Range

Manipulate[Range[n], {n,0,4}] 

https://preview.redd.it/z80dpm3gbdyd1.png?width=1024&format=png&auto=webp&s=603e6ded26bb3b2614034440c8dff5705e3d14ea

Suppose two or more sliders are needed, each displaying the same thing.

Or second slider will display:

Manipulate[Range[n], {n,0,3}] 

It will help if someone guides.

Update:

Took help of an AI tool with a response that apparently works:

-------------------------------------------------------------------------------

In Mathematica, you can create a `Manipulate` function with multiple sliders by adding additional control elements to your `Manipulate` expression. Here's how you can set it up to have two sliders, where each slider controls a different `Range` function.

### Example with Two Sliders

If you want to create two sliders, one that controls `n1` ranging from 0 to 4 and another that controls `n2` ranging from 0 to 3, you can use the following code:

```mathematica
Manipulate[
{Range[n1], Range[n2]},
{n1, 0, 4},
{n2, 0, 3}
]
```

### Explanation

- `Manipulate` is the function that creates interactive controls.

- `{Range[n1], Range[n2]}` specifies the output, which will show the two ranges based on the slider values.

- `{n1, 0, 4}` defines the first slider (`n1`) that goes from 0 to 4.

- `{n2, 0, 3}` defines the second slider (`n2`) that goes from 0 to 3.

### Additional Example with Multiple Sliders Displaying Same Range

If you want multiple sliders that all control the same output, you can do something like this:

`

``mathematica
Manipulate[
Range[n],
{n, 0, 4},
ControlPlacement -> Top
]

```

In this example, you can duplicate the slider control for a different purpose or display:

```mathematica
Manipulate[
{Range[n1], Range[n2]},
{{n1, 0, "First Range"}, 0, 4},
{{n2, 0, "Second Range"}, 0, 3}
]
```

### Customizing Labels

The additional part in the curly braces allows you to add a label to each slider for clarity, making it more user-friendly.

### Conclusion

With this approach, you can create multiple sliders and display their outputs in a `Manipulate` interface in Mathematica. Adjust the ranges and controls according to your specific requirements!

-----------------------------------------------------------------------------------------

0 Comments
2024/11/01
22:40 UTC

0

Replacing range values with a constant text string

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

Trying to replace each element with 'x'.

{x}

{x, x}

.....

{x, x, x, x, x, x, x, x, x, x}

2 Comments
2024/11/01
06:23 UTC

0

Logic/ Aussagenlogik Mathematik

Three people, A, B, and C, make the following statements: • A says: "B and C are telling the truth." • B says: "A is telling the truth." • C says: "A is lying, and B is telling the truth." Using propositional logic, determine who is lying and who is telling the truth.

Or in German: Drei Personen A B und C sagen folgendes:

A sagt B und C sagen die Wahrheit B sagt A sagt die Wahrheit C sagt A lügt B sagt die Wahrheit

Wer lügt wer sagt die Wahrheit? Finde das heraus mittels Aussagenlogik

1 Comment
2024/10/31
14:05 UTC

1

Table with range as iterator

https://preview.redd.it/4yc0hv5663yd1.png?width=1024&format=png&auto=webp&s=a3e972a542a95bc37c60658c54423074add2949f

Based on this code:

Table[Table[Orange,h],{h,0,5,1}] 

I am trying to modify so as to get this output:

{1}, {1,2},{1,2,3},{1,2,3,4}

Coded this but seems syntactical error and will not display what is desired:

Table[Range[4]] 

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

3 Comments
2024/10/31
12:48 UTC

1

Manipulate to show a column of 1 and 10 copies of x

Manipulate[Column[{x}], {x, 1,10,1}] 

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

Instead of integers, it is needed to display x. For instance when x is 5, it will display as follow:

https://preview.redd.it/m9ug76tcoxxd1.png?width=1024&format=png&auto=webp&s=75b9c904e5a535922754afa06f64b39e97ddf8cc

Although seeking reply for an exercise is not seen good, still going ahead as part of learning.

Also if anyone can explain the use of curly braces.

[Column[{x}]

Is the above curly brace has something to do with list data type that has curly braces?

Also:

 {x, 1,10,1}

I mean are curly braces in the above two are just for formatting (nothing to do with list data type) or they have something to do with list data type?

1 Comment
2024/10/30
18:07 UTC

1

Implication of ListPlot function in this example

Manipulate[ListPlot[range[n]],{n,5,50}] 

https://preview.redd.it/oiq6pcyxfxxd1.png?width=1024&format=png&auto=webp&s=7fab3e1728b1eee7ff6cc11285de14216abd0c80

As could be seen from the screenshot, the code running but giving output of little use.

2 Comments
2024/10/30
17:21 UTC

1

How to cite Mathematica in a math paper

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?

6 Comments
2024/10/30
12:28 UTC

2

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

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.

4 Comments
2024/10/30
12:27 UTC

15

I want to learn Mathematica; Where to start?

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

11 Comments
2024/10/30
05:11 UTC

5

Dumbfounded on why this integral is not evaluating properly

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

https://preview.redd.it/uwlql9k60dxd1.png?width=244&format=png&auto=webp&s=ecfb0a44f583a2c5d3ecb4574116376cdab75db0

https://preview.redd.it/jlsp499wwcxd1.png?width=678&format=png&auto=webp&s=8230fdf7f81970f49123fdc38b7680ce0fc72f43

https://preview.redd.it/gai1v7laxcxd1.png?width=672&format=png&auto=webp&s=f620e105ba012cb4b752dcdc6bdfd36ff5318290

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

https://preview.redd.it/gmnq6zrixcxd1.png?width=408&format=png&auto=webp&s=77b035170f546ebb2facccf8e4ee527800e1bcc9

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))

https://preview.redd.it/cv13ewoyxcxd1.png?width=587&format=png&auto=webp&s=001dff2f350c2d1b200d0a1b0a62667c640f1977

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

https://preview.redd.it/f17v3ag7ycxd1.png?width=666&format=png&auto=webp&s=091d755a6e8f420ce9e9acf0453fbf4ff37dcad9

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?

4 Comments
2024/10/27
20:29 UTC

2

Indefinite Integral of Sech in Version 14.1

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!

4 Comments
2024/10/23
07:19 UTC

8

Why isnt this working?

https://preview.redd.it/rk8k7e4bu4wd1.png?width=1150&format=png&auto=webp&s=d58f281e6fefd58a60b787f0540e33a7b3862b72

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?

8 Comments
2024/10/21
16:06 UTC

Back To Top