|
2.3.1 First stepsOnce SINGULAR is started, it awaits an input after the prompt
37+5; → 42 All objects have a type, e.g., integer variables are defined by
the word int k = 2; Test for equality resp. inequality is done using k == 2; → 1 k != 2; → 0 The value of an object is displayed by simply typing its name. k; → 2 On the other hand the output is suppressed if an assignment is made. int j; j = k+1; The last displayed (!) result is always available
with the special symbol 2*_; // the value from k displayed above → 4 Text starting with The whole manual is available online by typing the command help intmat; This shows the text of intmat, in the printed manual. Next, we define a 3 × 3 matrix of integers and initialize it with some values, row by row from left to right: intmat m[3][3] = 1,2,3,4,5,6,7,8,9; A single matrix entry may be selected and changed using
square brackets m[1,2]=0; m; → 1,0,3, → 4,5,6, → 7,8,9 To calculate the trace of this matrix, we use a int tr; for ( j=1; j <= 3; j++ ) { tr=tr + m[j,j]; } tr; → 15 Variables of type string can also be defined and used without a ring
being active. Strings are delimited by "example for strings:"; → example for strings: string s="The element of m "; s = s + "at position [2,3] is:"; // concatenation of strings by + s , m[2,3] , "."; → The element of m at position [2,3] is: 6 . s="m[2,1]=0; m;"; execute(s); → 1,0,3, → 0,5,6, → 7,8,9 This example shows that expressions can be separated by |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |