Mathematica: I made a program, but can't manipulate it. Please help

In summary, a program was created to accept a number between 3 and 18 and return the ways in which it can be obtained by throwing three dice simultaneously and adding the face values. The user was having trouble manipulating this number using ordinary code and sought help in identifying any errors. A possible solution was suggested using a defined function to evaluate different values of the number.
  • #1
gikiian
98
0
The program I wrote accepts a certain number between 3 and 18.
Then it returns the ways this number can be obtained by throwing three dice simultaneously and adding the face values.
I want to manipulate this number, :biggrin:
but can't achieve it using the ordinary code of manipulation. :grumpy:

I tried to find any error, but really wasn't able to figure out where have I gone wrong. :confused:

Need help!

Code:
j = 0;
For [
      x = 1, 
      x <= 6, 
      x++, 
      For [ 
            y = 1, 
            y <= 6, 
            y++, 
            For [ 
                  z = 1, 
                  z <= 6, 
                  z++,
                  {
                   If [ 
                       x + y + z == 5,  (*accepts the required sum of the face values*)
                       { 
                        If [
                            j + 1 <= 9, 
                            Print [j + 1, ".", "   ", x , " ", y, " " , z ], 
                            Print [j + 1, ".", "  ", x , " ", y, " " , z ]
                           ], 
                        j++
                       }    
                      ]
                  }
                 ]
           ]
     ]
 
Last edited:
Physics news on Phys.org
  • #2
You could define a function, and then evaluate it for different values, like this:

Code:
f[w_] :=
 Module[{j = 0},
  For[x = 1, x <= 6, x++, 
   For[y = 1, y <= 6, y++, 
    For[z = 1, z <= 6, 
     z++, {If[
       x + y + z == 
        w,(*accepts the required sum of the face values*){If[
         j + 1 <= 9, Print[j + 1, ".", "   ", x, " ", y, " ", z], 
         Print[j + 1, ".", "  ", x, " ", y, " ", z]], j++}]}]]]]

f[5]

1.   1 1 3

2.   1 2 2

3.   1 3 1

4.   2 1 2

5.   2 2 1

6.   3 1 1

f[3]

1.   1 1 1

f[4]

1.   1 1 2

2.   1 2 1

3.   2 1 1
 

1. Why am I unable to manipulate my program in Mathematica?

There could be a few reasons why you are unable to manipulate your program in Mathematica. One possibility is that your program contains errors or bugs that are preventing it from running properly. Another possibility is that you have not properly defined all the necessary variables and functions for your program to be manipulated. It is recommended to check your program for errors and make sure all necessary components are properly defined.

2. How can I fix errors in my Mathematica program?

To fix errors in your Mathematica program, you can use the built-in debugger tool. This allows you to step through your code and identify where the error is occurring. You can also use the Wolfram Language function "Check" to detect and handle errors in your program. Additionally, you can refer to the Mathematica documentation or seek help from the online community for troubleshooting tips.

3. Can I manipulate a program that uses external data in Mathematica?

Yes, you can manipulate a program that uses external data in Mathematica. The program must first import the external data using the appropriate function, such as "Import" or "URLExecute". Once the data is imported, you can use it in your program and manipulate it as needed.

4. How do I manipulate a specific part of my program in Mathematica?

To manipulate a specific part of your program in Mathematica, you can use the "Dynamic" function. This allows you to create interactive elements that can be changed and updated in real-time. You can also use the "Manipulate" function to create a dynamic interface for manipulating specific parts of your program.

5. What is the best way to learn how to manipulate programs in Mathematica?

The best way to learn how to manipulate programs in Mathematica is by practicing and exploring the built-in functions and tools. The Wolfram Language Documentation Center is a great resource for learning about different functions and how to use them. You can also take online courses or seek help from the online community for tips and guidance. Additionally, experimenting with sample programs and modifying them can also help improve your skills in program manipulation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
258
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Programming and Computer Science
Replies
4
Views
609
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top