[Mathematica] Multiples of 5 from 0 to 100

  • Thread starter Thread starter adjacent
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
To calculate the multiples of 5 from 0 to 100 in Mathematica, users can utilize the Array function, specifically with expressions like Array[5*(#-1)&,21] or Array[5*#&,21,0]. The discussion highlights that the Mod function should use "==" for comparisons, and the "&" symbol denotes a pure function, with "#" representing the function's argument. Users also explored how to format the output in a table rather than printing each result on a new line. Additionally, there was interest in creating an executable application, but it was noted that this would require the entire Mathematica engine.
adjacent
Gold Member
Messages
1,552
Reaction score
62
I have downloaded Mathematica to see if it is really that good. Many people use it.
I want to calculate the multiples of 5 from 0 to 100.
This seems pretty simple but I can't figure out a way to do it.
I can't use the Modulo % in mathematica.
I know that I should use Table. Is there any other function?
I have searched google too, but could not find a solution. If project euler was online, it would have been so helpful!

Please bear with me, I have never touched Mathematica until now.

I tried this code , but it does not work;
Code:
For[i = 0, i <= 100, i++,
 If[Mod[i, 5] = 0, Print[i], Print["Not found"]
  ]
 
Last edited:
Technology news on Phys.org
Mathematica is great - but it's been almost a decade since I last used it.
I think what you want is something like this:

Array[5*(#-1)&,21]

or

Array[5*#&,21,0]
 
Last edited:
  • Like
Likes 1 person
In your version, try "Mod[i,5] == 0".
 
  • Like
Likes 1 person
.Scott said:
Mathematica is great - but it's been almost a decade since I last used it.
I think what you want is something like this:

Array[5*(#-1)&,21]

or

Array[5*#&,21,0]
This works, but I don't understand that code. Can you explain?
What is the need of 21 here? What is #?(Slot 1)? What is &?

Ah, my method also works now.I thought mathematica does not use ==. How will I arrange them in a table now, instead of printing on a new line?
Edit:
This is my code now
Code:
n = 10;
m = 5;
For[i = 1, i <= n, i++, If[Mod[i, m] == 0, Print[i], null]]
 
Last edited:
The first argument to array is the function that will generate the values.
The second argument is the size of the array. The set 0,5,10,...,100 has 21 elements.
If there is a third argument and it is a simple number, it is the starting index to a 1-dimensional array. Otherwise the index starts at 1.

For that first argument, the & at the end of the expression identifies it as a pure function. The # is a reference to the only argument o the function - which for the array syntax is the array index. If the pure function had more than one argument, references to those arguments would be #1, #2, ...
 
  • Like
Likes 1 person
.Scott said:
The first argument to array is the function that will generate the values.
The second argument is the size of the array. The set 0,5,10,...,100 has 21 elements.
If there is a third argument and it is a simple number, it is the starting index to a 1-dimensional array. Otherwise the index starts at 1.

For that first argument, the & at the end of the expression identifies it as a pure function. The # is a reference to the only argument o the function - which for the array syntax is the array index. If the pure function had more than one argument, references to those arguments would be #1, #2, ...

Thank you so much. I have managed to perfect the code:
Code:
m = 3;
n = 25;
Array[m*#1 &, Floor[(n/m)]]
 
By George, I think you've got it!
 
.Scott said:
By George, I think you've got it!

Now is there any way to make an application with this?
An .exe file?
 
adjacent said:
Now is there any way to make an application with this?
An .exe file?
I'm pretty sure there isn't. You would pretty much need the entire Mathematica engine.
 
  • #10
.Scott said:
I'm pretty sure there isn't. You would pretty much need the entire Mathematica engine.

I think there is something named "CDF Player"- Downloading now.
I am now realising how great Mathematica is. Far greater than I expected!
 
  • #11
adjacent said:
I think there is something named "CDF Player"- Downloading now.
I am now realising how great Mathematica is. Far greater than I expected!
If you have some sort of calculus problem, the combination of human skill and pattern recognition and Mathematica's unerring, encyclopedic, and deep analysis just makes the game a whole lot easier.
 
Back
Top