Problems with mathematica code

In summary, the conversation discusses using Markov models to evaluate a device and using code from a paper by H. Timbley. The code is provided but when the next section is typed in, error codes appear. The issue seems to be that randomUser is not defined. The paper and version of Mathematica used are not specified.
  • #1
johalia
1
0
Hello!

I'm writing a paper where I'm going to use markov models to evalute a device. My base for this paper is the paper written by H. Timbley. I have never used Mathematica before and thought that I would start by trying the complete code that Timbley has written in the appendix of the paper. The code is:

DiscreteMath`Combinatorica`;
IndexOf[vector , e ] := Position[vector, e][[1, 1]];

device =
{{"Clock", "Clock", "Clock", "Clock", "Clock", "Clock"},
{"Quick Defrost", "Quick Defrost", "Quick Defrost",
"Quick Defrost", "Quick Defrost", "Quick Defrost"},
{"Timer1", "Timer1", "Timer2", "Timer1", "Timer2", "Timer1"},
{"Clock", "Clock", "Clock", "Clock", "Clock", "Clock"},
{"Clock", "Quick Defrost", "Power1",
"Power2", "Power1", "Power2"}
};

buttonNames = {"Clock", "Quick Defrost", "Time", "Clear", "Power"};
stateNames = {"Clock", "Quick Defrost", "Timer1", "Timer2", "Power1",
"Power2"};

numberOfStates = Length@stateNames;
numberOfButtons = Length@buttonNames;

start = IndexOf[stateNames, "Power1"];
goal = IndexOf[stateNames, "Power2"];


Until then the code work just fine, but when I type in the next section described in the appendix (see below), some error codes pop up.

Do[randomUser[[i, IndexOf[stateNames, device[[b, i]]]]] +=
1/numberOfButtons, {b, numberOfButtons}, {i, numberOfStates}];


Error codes:
Part::partw: Part 1 of {} does not exist. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::partw: Part 1 of {} does not exist. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::partw: Part 3 of {Quick Defrost,(Quick Defrost)^5} does not exist. >>
General::stop: Further output of Part::partw will be suppressed during this calculation. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
General::stop: Further output of Part::pspec will be suppressed during this calculation. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
General::stop: Further output of Set::pspec will be suppressed during this calculation. >>


Is there anybody that could tell me what's wrong with the code?
 
Last edited:
Physics news on Phys.org
  • #2
What version of Mathematica are you using? Because I get different error messages.

The problem seems to be that randomUser is not defined.

Can you give a reference for the paper you mention?
 

1. What are some common mistakes that cause problems with mathematica code?

Some common mistakes that can cause problems with mathematica code include:

  • Missing or incorrect syntax, such as missing parentheses or brackets
  • Using incorrect or undefined variable names
  • Attempting to perform operations on incompatible data types
  • Forgetting to define necessary functions or importing necessary packages
  • Using incorrect or outdated versions of functions or packages

2. How can I troubleshoot errors in my mathematica code?

Some steps you can take to troubleshoot errors in your mathematica code include:

  • Checking for syntax errors and typos
  • Using the built-in debugging tools, such as the "Trace" function
  • Using "Print" statements to track the value of variables throughout the code
  • Consulting the documentation or online resources for the specific function or package you are using
  • Asking for help from other mathematica users or the mathematica community

3. How can I improve the efficiency of my mathematica code?

Some ways to improve the efficiency of your mathematica code include:

  • Using built-in mathematica functions instead of writing your own code
  • Using vectorization and functional programming techniques
  • Avoiding unnecessary loops
  • Using "Compile" to create optimized versions of your code for specific data types
  • Using parallel processing techniques

4. How can I handle large datasets in mathematica?

Some techniques for handling large datasets in mathematica include:

  • Using the "Dataset" function for efficient storage and manipulation of data
  • Using "Import" and "Export" functions to read and write data from external files
  • Using the "ParallelMap" and "ParallelTable" functions to process data in parallel
  • Using the "MemoryConstraint" option to limit the amount of memory used by your code
  • Splitting large datasets into smaller chunks and processing them separately

5. How can I prevent my mathematica code from crashing?

To prevent your mathematica code from crashing, you can:

  • Check for and handle potential errors or exceptions
  • Use appropriate data types and avoid operations on incompatible data types
  • Limit memory usage by using the "MemoryConstraint" option or breaking up large datasets
  • Use techniques to improve code efficiency and speed, such as parallel processing and vectorization
  • Regularly save your work to avoid losing progress in case of a crash

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
976
Replies
0
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
Replies
1
Views
3K
Replies
16
Views
2K
Back
Top