pickmop.blogg.se

Wolfram mathematica function
Wolfram mathematica function













wolfram mathematica function

The # here stands first for the initial x, and afterwards for the previous 3 x + 4 that becomes the new x. This will also work in Wolfram Alpha: NestList

wolfram mathematica function wolfram mathematica function

What if you want to iterate 3 x + 4 a few times, starting with x = 3 and feeding the result into the next x? In Mathematica, you can use NestList. To let Mathematica know we’re invoking a pure function, we need to put & before Select’s closing brace. The # “pulls in” a number from the list, multiplies it by 3 and adds 4 (you can write 3 * # + 4 if you prefer). Then Select tells Mathematica that we want it to select from that list the elements that return True for the given Boolean, in this case PrimeQ &. So Range just gives us the integers 1 to 100, and Prime] gives us the primes indexed by the integers 1 to 100, that is, 2, 3, 5, 7, 11, 13, 17, 19, and so on to 541. Wolfram Alpha gives the correct response to the Wolfram Mathematica statement above: 3, 5, 11, 13, 19, and so on and so forth to 541, which just happens to be the 100th prime number. By contrast, we see that 7 is not such a prime, since 3 × 7 + 4 = 25 = 5². For example, 5 is such a prime, since 3 × 5 + 4 = 19. This is probably what you would type in if you’re curious about which prime numbers p also give primes for 3 p + 4. In fact, go to Wolfram Alpha right now and type this in: Select], PrimeQ &] In Wolfram Mathematica, there’s this concept called “ pure functions.” With some caveats, you can use pure functions in Wolfram Alpha. For those of you with lots of experience with Wolfram Mathematica, this might be old hat.īut for those of you who sometimes play around with functional programming with Wolfram Alpha or Scastie or whatever else you use to play around with functional programming, this might be a revelation. Short post, just wanted to share a neat little discovery I made earlier today.















Wolfram mathematica function