Numerical Simulation example guide

Numerical Simulation utilizes a Program Model that enables simulations using an expressive programming language of Maxima which is based on Lisp.

This article will cover a variety of the most common variable types.

Variable Basics

Question

James has 2 apples. Amy has twice as many. How many does Amy have?

jamesApples: 2;

amyApples: jamesApples * 2;

Programme Input =

jamesApples

Candidate Input =

amyApples is CORRECT

 

Random Variables

random(n)
  • Set n as a positive integer. An integer between 0 up to but not including the number will be randomly generated.

 

rand(n.0)
  • Set n as a positive integer and a floating point will be generated between 0.0 and n.0.

 

rand([n0,n1,n3,n7,n8])
  • Set a list of numbers from which one will be randomly selected.

 

rand_with_step(lower,upper,step)
  • Set a number range with lower and upper limits, and the value increase between each number in between. One of these values will be randomly generated.

 

rand_with_prohib(lower,upper,[n0,n1..])
  • Set a number range with lower and upper limits using an integer, and in square brackets list the integers to exclude.

 

Examples

myVar: random(5);
  • Possible results for myVar = 0, 1, 2, 3, 4

 

myVar: rand(2.0);
  • Possible results for myVar = 0.12…, 0.022…, 1.98…, 1.47… etc.

 

myVar: rand([2,4.5,3,1000]);
  • Possible results for myVar = 2, 3, 4.5, 10000

 

myVar: rand_with_step(-3,3,1);
  • Possible results for myVar = -3, -2, -1, 0, 1, 2, 3

 

myVar: Rand_with_step(0.5,3,0.5);
  • Possible results for myVar = 0.5, 1.0, 1.5, 2.0, 2.5, 3.0

 

myVar: rand_with_prohib(1,10,[5,6,7]);
  • Possible results for myVar = 1, 2, 3, 4, 8, 9, 10

 

Rounding

decimalplaces(myVar, n)
  • Define your variable or value and n rounds the value to that many decimal places.

 

Examples

myVar = 1.5237;

roundedVar: decimalplaces(myVar, 2);

Result = 1.52

 

roundedVar: decimalplaces(1.5237, 3);

Result = 1.53

 

Articles in this section

Was this article helpful?
2 out of 2 found this helpful