[Mathematica] Multiples of 5 from 0 to 100

  • Thread starter Thread starter adjacent
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around using Mathematica to calculate the multiples of 5 from 0 to 100. Participants explore different methods and functions available in Mathematica, share code snippets, and seek clarification on specific syntax and functionality.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant expresses difficulty in using Mathematica for calculating multiples of 5 and mentions not being able to use the Modulo function.
  • Another participant suggests using the Array function with different syntaxes to generate the desired multiples.
  • A correction is made regarding the use of "==" instead of "=" in the Mod function.
  • Clarification is provided about the Array function, including the role of the pure function syntax and the significance of the array size.
  • One participant shares their updated code after resolving initial issues and expresses satisfaction with their progress.
  • There are inquiries about creating an executable application from the Mathematica code, with some participants indicating that it may not be feasible without the entire Mathematica engine.
  • Discussion includes a mention of "CDF Player" as a potential tool related to Mathematica.

Areas of Agreement / Disagreement

Participants generally agree on the effectiveness of Mathematica and share successful methods for generating multiples of 5. However, there is no consensus on the feasibility of creating an executable application from Mathematica code.

Contextual Notes

Some participants express uncertainty about specific syntax and functionality in Mathematica, indicating a learning curve associated with the software.

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   Reactions: 1 person
In your version, try "Mod[i,5] == 0".
 
  • Like
Likes   Reactions: 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   Reactions: 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.
 

Similar threads

Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 18 ·
Replies
18
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K