/r/Mathematica
For information and tips about Mathematica features.
related reddits:
/r/Mathematica
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!
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.
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:
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.
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.
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
BarChart[StringLength[StringSplit["A long time ago, in a galaxy far,far away"]]]
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).
ImageAdd[
Negate[EdgeDetect[Import["https://wolfr.am/EIWL-SW-Image"]]],
Import["https://wolfr.am/EIWL-SW-Image"]
]
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.
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.
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]
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?
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.
#^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.
Without label, this is the code:
Manipulate[
ColorData["Rainbow"][#] & /@ Rescale[Range[1, n], {1, n}, {0, 1}],
{n, 5, 50, 1}
]
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"}.
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
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.
It will help if anyone can confirm and if indeed replaceable, which command or code to replace.
Manipulate[n,{n,1000,9999,1}]
The output needs to be in list form:
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 Pick
ing which 1,3,7,9 indices are allowed as valid n-length subsequences.
Manipulate[Range[n], {n,0,4}]
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!
-----------------------------------------------------------------------------------------
Trying to replace each element with 'x'.
{x}
{x, x}
.....
{x, x, x, x, x, x, x, x, x, x}
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
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]]
Manipulate[Column[{x}], {x, 1,10,1}]
Instead of integers, it is needed to display x. For instance when x is 5, it will display as follow:
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?
Manipulate[ListPlot[range[n]],{n,5,50}]
As could be seen from the screenshot, the code running but giving output of little use.
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?
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.
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
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?
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!
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?