Difference between revisions of "OpenModelica/C2/Arrays-in-Modelica/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 15: Line 15:
 
|| In this tutorial, we are going to learn:
 
|| In this tutorial, we are going to learn:
  
* How to declare '''array''' variables
+
* How to declare '''array''' variables,
* How to construct '''arrays'''
+
* How to construct '''arrays''',
 
* How to use '''for''' and '''while''' loops and
 
* How to use '''for''' and '''while''' loops and
* How to use '''OMShell'''
+
* How to use '''OMShell'''.
  
 
|-
 
|-
Line 34: Line 34:
  
 
Prerequisites
 
Prerequisites
|| To understand and practice this tutorial,
+
|| To understand and practice this tutorial:
  
* you need knowledge of arrays in any programming language
+
* you need knowledge of '''arrays''' in any programming language.
* You need to know how to define a class in Modelica
+
* You need to know how to define a '''class''' in '''Modelica'''.
  
 
Prerequisite tutorials are mentioned on our website.
 
Prerequisite tutorials are mentioned on our website.
Line 47: Line 47:
  
 
'''Vector''' declaration (Add an example in the slide for declaration as well)
 
'''Vector''' declaration (Add an example in the slide for declaration as well)
|| '''Vector''' is a one dimensional array
+
|| '''Vector''' is a one dimensional array.
 +
.
 +
It has single index.
  
It has single index
+
'''Syntax''' for vector declaration is as shown.  
 
+
Syntax for vector declaration is as shown.  
+
  
 
The example shown declares a vector variable '''a''' whose size is '''2'''.
 
The example shown declares a vector variable '''a''' whose size is '''2'''.
  
A vector can be constructed by including the elements in curly braces.
+
A '''vector''' can be constructed by including the elements in curly braces.
  
This example defines a vector parameter '''a''' with '''2''' and '''3''' as its elements.
+
This example defines a '''vector''' parameter '''a''' with '''2''' and '''3''' as its elements.
  
 
|-
 
|-
Line 63: Line 63:
  
 
'''Indexing vector elements'''
 
'''Indexing vector elements'''
|| To access the elements of a vector, it is necessary to understand indexing.
+
|| To access the elements of a '''vector''', it is necessary to understand '''indexing'''.
  
Syntax for vector indexing is as shown.
+
'''Syntax''' for '''vector indexing''' is as shown.
  
Vector indexing starts from '''1''' and
+
'''Vector indexing''' starts from '''1''' and
  
Indices must be integers.  
+
'''Indices''' must be '''integers'''.  
  
 
|-
 
|-
 
|| '''Problem Statement'''
 
|| '''Problem Statement'''
|| Let us develop a function named '''polynomialEvaluatorUsingVectors'''.  
+
|| Let us develop a '''function''' named '''polynomialEvaluatorUsingVectors'''.  
  
This function is an extension of '''polynomialEvaluator''' function which was discussed in previous tutorials.  
+
This '''function''' is an extension of '''polynomialEvaluator''' function which was discussed in previous tutorials.  
  
 
We shall replace parameters '''a,b''' and '''c''' of '''polynomialEvaluator''' with a vector '''a'''.
 
We shall replace parameters '''a,b''' and '''c''' of '''polynomialEvaluator''' with a vector '''a'''.
Line 81: Line 81:
 
|-
 
|-
 
||  
 
||  
|| Please download and save all the files available on our Code Files link.  
+
|| Please download and save all the files available on our '''Code Files''' link.  
  
 
For your convenience, '''polynomialEvaluator''' function is also made available.
 
For your convenience, '''polynomialEvaluator''' function is also made available.
Line 89: Line 89:
 
|| Now let me switch to '''OMEdit''' to demonstrate this function.
 
|| Now let me switch to '''OMEdit''' to demonstrate this function.
  
OMEdit is now open in Welcome perspective.  
+
'''OMEdit''' is now open in '''Welcome''' perspective.  
  
 
I have opened all the necessary files.  
 
I have opened all the necessary files.  
  
Note that the following classes or functions are now open in OMEdit: '''functionTester''', '''matrixAdder''',  '''polynomialEvaluator''' and  '''polynomialEvaluatorUsingVectors'''.
+
Note that the following classes or functions are now open in OMEdit:  
 +
 
 +
'''functionTester''',  
 +
 
 +
'''matrixAdder''',   
 +
 
 +
'''polynomialEvaluator''' and   
 +
 
 +
'''polynomialEvaluatorUsingVectors'''.
  
 
|-
 
|-
Line 106: Line 114:
 
|| Now, to view them let me double click on each icon.  
 
|| Now, to view them let me double click on each icon.  
  
Let me shift the OMEdit window to the left for better visibility.
+
Let me shift the '''OMEdit''' window to the left for better visibility.
  
 
Go to '''polynomialEvaluator''' tab.  
 
Go to '''polynomialEvaluator''' tab.  
Line 112: Line 120:
 
Open it in '''Text View'''.
 
Open it in '''Text View'''.
  
For more information on this function, refer to the previous tutorials.  
+
For more information on this '''function''', refer to the previous tutorials.  
  
 
|-
 
|-
Line 127: Line 135:
 
'''output Real fx;'''
 
'''output Real fx;'''
  
|| Input and output variables are the same as in '''polynomialEvaluator''' function.
+
|| '''Input''' and '''output''' variables are the same as in '''polynomialEvaluator''' function.
  
 
|-
 
|-
 
|| '''protected parameter Real a[3]''' = {1,2,1};  
 
|| '''protected parameter Real a[3]''' = {1,2,1};  
|| Parameters '''a,b''' and '''c''' of polynomialEvaluator are replaced with a vector '''a'''.
+
|| Parameters '''a,b''' and '''c''' of '''polynomialEvaluator''' are replaced with a vector '''a'''.
  
 
|-
 
|-
Line 141: Line 149:
 
|| The elements of this vectors are included in curly braces as shown.  
 
|| The elements of this vectors are included in curly braces as shown.  
  
The elements are separated by a comma.
+
The elements are separated by a '''comma'''.
 
+
|-
+
|| '''algorithm'''
+
 
+
'''fx := a[1]*x^2 + a[2]*x + a[3];'''
+
|| This indicates the beginning of algorithm section.
+
 
+
The elements of vector a are accessed using their indices.
+
  
 
|-
 
|-
Line 155: Line 155:
  
 
fx := '''a[1]'''<nowiki>*x^2 + a[2]*x + a[3];</nowiki>
 
fx := '''a[1]'''<nowiki>*x^2 + a[2]*x + a[3];</nowiki>
|| In the assignment statement the elements of vector '''a''' are accessed using their indices.
+
|| In the '''assignment''' statement the elements of vector '''a''' are accessed using their indices.
  
a[1] is the first element of vector a.
+
'''a[1]''' is the first element of vector '''a'''.
  
 
|-
 
|-
Line 179: Line 179:
 
|-
 
|-
 
|| '''z = polynomialEvaluatorUsingVectors(10);'''
 
|| '''z = polynomialEvaluatorUsingVectors(10);'''
|| '''polynomialEvaluatorUsingVectors''' function is called with an input argument of '''10''' units.
+
|| '''polynomialEvaluatorUsingVectors''' function is called with an '''input''' argument of '''10''' units.
  
 
|-
 
|-
 
|| '''z = polynomialEvaluatorUsingVectors(10);'''
 
|| '''z = polynomialEvaluatorUsingVectors(10);'''
|| The value returned by this function is equated to z.
+
|| The value returned by this function is equated to '''z'''.
  
 
Now let me Simulate this class.
 
Now let me Simulate this class.
Line 198: Line 198:
 
Select '''z''' in the variables browser
 
Select '''z''' in the variables browser
  
|| '''functionTester''' class is simulated.
+
|| Select '''z''' in the variables browser.
 
+
Select '''z''' in the variables browser.
+
  
Note that the value of z is equal to '''f(x)''' at '''x = 10'''.
+
Note that the value of '''z''' is equal to '''f(x)''' at '''x = 10'''.
  
This plot is the same as observed in case of polynomialEvaluator function.
+
This plot is the same as observed in the case of '''polynomialEvaluator''' function.
  
Now let me de-select z and delete the result.
+
Now let me de-select '''z''' and delete the result.
  
 
|-
 
|-
Line 221: Line 219:
 
'''for loop''' (Add another slide for syntax)
 
'''for loop''' (Add another slide for syntax)
  
|| '''for''' loop is used to iterate statements a given number of times
+
|| '''for''' loop is used to iterate statements a given number of times.
  
It can be used in algorithm and equation sections.
+
It can be used in '''algorithm''' and '''equation''' sections.
  
Syntax for '''for''' loop is as shown with an example.  
+
'''Syntax''' for '''for''' loop is as shown with an example.  
  
 
|-
 
|-
 
||  
 
||  
|| To demonstrate how to use for loop let me go back to '''OMEdit'''.
+
|| To demonstrate how to use '''for''' loop let me go back to '''OMEdit'''.
  
 
|-
 
|-
Line 239: Line 237:
  
 
'''fx := a[1]*x^2 + a[2]*x + a[3]; '''
 
'''fx := a[1]*x^2 + a[2]*x + a[3]; '''
|| In the assignment statement for '''fx''', we are accessing the elements of vector '''a'''.  
+
|| In the '''assignment''' statement for '''fx''', we are accessing the elements of vector '''a'''.  
  
This can also be done using a for loop.  
+
This can also be done using a '''for''' loop.  
  
Now, let us see how to include a for loop in the algorithm section.
+
Now, let us see how to include a '''for''' loop in the '''algorithm''' section.
  
 
|-
 
|-
 
|| Comment // '''fx := a[1]*x^2 + a[2]*x + a[3]; '''
 
|| Comment // '''fx := a[1]*x^2 + a[2]*x + a[3]; '''
|| Firstly, Comment the assignment statement for '''fx''' by inserting double slash at the beginning and end.
+
|| Firstly, '''Comment''' the assignment statement for '''fx''' by inserting double slash at the beginning and end.
  
Save this function by pressing Ctrl+S.
+
Save this function by pressing '''Ctrl+S'''.
  
 
|-
 
|-
 
||  
 
||  
|| The for loop to be inserted has been provided in a text file named '''for-loop.txt'''.  
+
|| The '''for''' loop to be inserted has been provided in a text file named '''for-loop.txt'''.  
  
 
It is available on our website.
 
It is available on our website.
Line 259: Line 257:
 
I have opened this file using '''gedit'''.  
 
I have opened this file using '''gedit'''.  
  
Windows users may use notepad or any other text editor to open it.
+
Windows users may use '''notepad''' or any other text editor to open it.
  
 
|-
 
|-
Line 267: Line 265:
 
|-
 
|-
 
||  
 
||  
|| Copy all the statements by pressing Ctrl+C.
+
|| Copy all the statements by pressing '''Ctrl+C'''.
  
 
Go back to '''OMEdit'''
 
Go back to '''OMEdit'''
Line 299: Line 297:
 
|| This statement iteratively adds terms of the polynomial '''f(x)'''.
 
|| This statement iteratively adds terms of the polynomial '''f(x)'''.
  
Polynomial '''f(x)''' has been discussed while discussing polynomialEvaluator function.
+
Polynomial '''f(x)''' has been discussed while discussing '''polynomialEvaluator''' function.
  
 
|-
 
|-
 
|| '''// end for;'''
 
|| '''// end for;'''
|| This statement indicates the end of '''for''' loop
+
|| This statement indicates the end of '''for''' loop.
  
 
|-
 
|-
Line 311: Line 309:
 
To test this function let us use the class '''functionTester'''.
 
To test this function let us use the class '''functionTester'''.
  
I have made no changes to this function to this class.
+
I have made no changes to this function to this '''class'''.
  
 
|-
 
|-
Line 323: Line 321:
 
Note that the value of '''z''' remains the same after changes are made to the function.
 
Note that the value of '''z''' remains the same after changes are made to the function.
  
Let me de-select z and delete the result.
+
Let me de-select '''z''' and delete the result.
  
 
|-
 
|-
Line 350: Line 348:
 
|| Let us discuss '''Arrays''' now.
 
|| Let us discuss '''Arrays''' now.
  
'''Arrays''' are used to represent multi-dimensional data.
+
'''Arrays''' are used to represent '''multi-dimensional''' data.
  
They can be constructed using vector notation.
+
They can be constructed using '''vector''' notation.
  
 
|-
 
|-
Line 358: Line 356:
  
 
'''Syntax'''
 
'''Syntax'''
|| '''Syntax''' for array declaration and indexing is as shown.
+
|| '''Syntax''' for '''array''' declaration and '''indexing''' is as shown.
  
 
|-
 
|-
Line 364: Line 362:
  
 
'''Problem Statement'''
 
'''Problem Statement'''
|| To understated more about array construction and indexing
+
|| To understated more about '''array''' construction and '''indexing'''.
  
Let us write a class named '''matrixAdder''' which
+
Let us write a '''class''' named '''matrixAdder''' which
  
adds '''myMatrix''' and adder matrices to give '''mySum'''.
+
adds '''myMatrix''' and '''adder matrices''' to give '''mySum'''.
  
'''myMatrix''' and adder matrices are as shown.  
+
'''myMatrix''' and '''adder matrices''' are as shown.  
  
 
|-
 
|-
Line 386: Line 384:
 
|-
 
|-
 
|| '''parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}''';  
 
|| '''parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}''';  
|| '''myMatrix''' is a Real parameter array.  
+
|| '''myMatrix''' is a '''Real''' parameter array.  
  
 
|-
 
|-
 
|| '''parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}''';  
 
|| '''parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}''';  
|| Numbers in square bracket represent size of this array.
+
|| Numbers in square bracket represent size of this '''array'''.
  
 
The size of first dimension is '''3'''.  
 
The size of first dimension is '''3'''.  
  
Similarly, the size of second dimension is '''2'''
+
Similarly, the size of second dimension is '''2'''.
  
 
|-
 
|-
Line 422: Line 420:
 
|| To add this two arrays or matrices we need to access elements from two dimensions.  
 
|| To add this two arrays or matrices we need to access elements from two dimensions.  
  
Hence a '''nested for''' loop is required.
+
Hence '''a''' '''nested for''' loop is required.
  
 
|-
 
|-
Line 430: Line 428:
 
|-
 
|-
 
|| '''for j in 1:2 loop'''
 
|| '''for j in 1:2 loop'''
|| Similarly this for loop runs through the second dimension.
+
|| Similarly this '''for''' loop runs through the second dimension.
  
 
Let me scroll down a bit.
 
Let me scroll down a bit.
Line 436: Line 434:
 
|-
 
|-
 
|| '''mySum[i, j] := myMatrix[i, j] + adder[i, j]; '''
 
|| '''mySum[i, j] := myMatrix[i, j] + adder[i, j]; '''
|| Corresponding elements of '''myMatrix''' and adder matrices are added to yield '''mySum'''
+
|| Corresponding elements of '''myMatrix''' and '''adder matrices''' are added to yield '''mySum'''
  
 
|-
 
|-
Line 472: Line 470:
 
|| As an assignment:  
 
|| As an assignment:  
  
Write a function named '''vectorReversal''' to reverse the order of elements in a vector.
+
* Write a function named '''vectorReversal''' to reverse the order of elements in a vector.
  
Similarly write a function '''matrixReversal''' to reverse the order of elements in each row of a matrix.
+
* Similarly write a function '''matrixReversal''' to reverse the order of elements in each row of a matrix.
  
Write '''functionTester''' class to test these two functions.
+
* Write '''functionTester''' class to test these two functions.
  
 
|-
 
|-
 
||  
 
||  
|| This brings us to the end of this tutorial
+
|| This brings us to the end of this tutorial.
  
 
|-
 
|-
Line 490: Line 488:
 
['''http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org] /What\_is\_a\_Spoken\_Tutorial'''
 
['''http://spoken-tutorial.org/ http][http://spoken-tutorial.org/ ://][http://spoken-tutorial.org/ spoken][http://spoken-tutorial.org/ -][http://spoken-tutorial.org/ tutorial][http://spoken-tutorial.org/ .][http://spoken-tutorial.org/ org] /What\_is\_a\_Spoken\_Tutorial'''
  
It summarises the '''Spoken Tutorial''' project
+
It summarises the '''Spoken Tutorial''' project.
  
 
|-
 
|-
Line 496: Line 494:
  
 
'''Spoken Tutorial''' Workshops
 
'''Spoken Tutorial''' Workshops
|| We conducts workshops using spoken tutorials
+
|| We conducts workshops using spoken tutorials.
  
 
Give certificates.  
 
Give certificates.  

Revision as of 15:16, 16 March 2016

Visual Cue Narration
Slide:

Title Slide

Welcome to the spoken tutorial on Arrays.
Slide:

Learning Objectives

In this tutorial, we are going to learn:
  • How to declare array variables,
  • How to construct arrays,
  • How to use for and while loops and
  • How to use OMShell.
Slide:

System Requirements

To record this tutorial, I am using:
  • OpenModelica 1.9.2

You may use any of the following operating systems to practice this tutorial.

Slide:

Prerequisites

To understand and practice this tutorial:
  • you need knowledge of arrays in any programming language.
  • You need to know how to define a class in Modelica.

Prerequisite tutorials are mentioned on our website.

Please go through them.

Slide:

Vector declaration (Add an example in the slide for declaration as well)

Vector is a one dimensional array.

. It has single index.

Syntax for vector declaration is as shown.

The example shown declares a vector variable a whose size is 2.

A vector can be constructed by including the elements in curly braces.

This example defines a vector parameter a with 2 and 3 as its elements.

Slide:

Indexing vector elements

To access the elements of a vector, it is necessary to understand indexing.

Syntax for vector indexing is as shown.

Vector indexing starts from 1 and

Indices must be integers.

Problem Statement Let us develop a function named polynomialEvaluatorUsingVectors.

This function is an extension of polynomialEvaluator function which was discussed in previous tutorials.

We shall replace parameters a,b and c of polynomialEvaluator with a vector a.

Please download and save all the files available on our Code Files link.

For your convenience, polynomialEvaluator function is also made available.

/* Switch to OMEdit */ Now let me switch to OMEdit to demonstrate this function.

OMEdit is now open in Welcome perspective.

I have opened all the necessary files.

Note that the following classes or functions are now open in OMEdit:

functionTester,

matrixAdder,

polynomialEvaluator and

polynomialEvaluatorUsingVectors.

/* polynomialEvaluator */

protected parameter Real a = 1;

protected parameter Real b = 2;

protected parameter Real c = 1;

Now, to view them let me double click on each icon.

Let me shift the OMEdit window to the left for better visibility.

Go to polynomialEvaluator tab.

Open it in Text View.

For more information on this function, refer to the previous tutorials.

Let me go to polynomialEvaluatorUsingVectors.

Open it in Text View.

/* polynomialEvaluatorUsingVectors */

input Real x;

output Real fx;

Input and output variables are the same as in polynomialEvaluator function.
protected parameter Real a[3] = {1,2,1}; Parameters a,b and c of polynomialEvaluator are replaced with a vector a.
protected parameter Real a[3] = {1,2,1}; Size of this vector is 3.
protected parameter Real a[3] = {1,2,1}; The elements of this vectors are included in curly braces as shown.

The elements are separated by a comma.

algorithm

fx := a[1]*x^2 + a[2]*x + a[3];

In the assignment statement the elements of vector a are accessed using their indices.

a[1] is the first element of vector a.

fx := a[1]*x^2 + a[2]*x + a[3]; Similarly, the second element and third element of vector a have been accessed as well.
Now, let me switch to functionTester tab.

Open it in Text View.

This class is similar to the functionTester class discussed in previous tutorial.

/* functionTester */

Real z;

z is a Real variable.
z = polynomialEvaluatorUsingVectors(10); polynomialEvaluatorUsingVectors function is called with an input argument of 10 units.
z = polynomialEvaluatorUsingVectors(10); The value returned by this function is equated to z.

Now let me Simulate this class.

Click on Simulate button Click on Simulate button.

Close the pop up window.

/* Plotting perspective */

Select z in the variables browser

Select z in the variables browser.

Note that the value of z is equal to f(x) at x = 10.

This plot is the same as observed in the case of polynomialEvaluator function.

Now let me de-select z and delete the result.

Go back to Modeling perspective Go back to Modeling perspective
Now let me switch to the slides.
Slide:

for loop (Add another slide for syntax)

for loop is used to iterate statements a given number of times.

It can be used in algorithm and equation sections.

Syntax for for loop is as shown with an example.

To demonstrate how to use for loop let me go back to OMEdit.
Click on polynomialEvaluatorUsingVectors tab.
/* polynomialEvaluatorUsingVectors */

fx := a[1]*x^2 + a[2]*x + a[3];

In the assignment statement for fx, we are accessing the elements of vector a.

This can also be done using a for loop.

Now, let us see how to include a for loop in the algorithm section.

Comment // fx := a[1]*x^2 + a[2]*x + a[3]; Firstly, Comment the assignment statement for fx by inserting double slash at the beginning and end.

Save this function by pressing Ctrl+S.

The for loop to be inserted has been provided in a text file named for-loop.txt.

It is available on our website.

I have opened this file using gedit.

Windows users may use notepad or any other text editor to open it.

Let me go to gedit.
Copy all the statements by pressing Ctrl+C.

Go back to OMEdit

Press Enter.

Paste all the statements by pressing Ctrl + V.

Save this function by pressing Ctrl + S.

// fx := 0; Now, let me explain each statement of this loop.

This statement assigns fx an initial value of zero before the loop starts.

// for i in 1:3 loop Here, i serves as a loop counter.

The loop runs until value of i is 3.

It is not necessary to declare i before it is used.

Let me scroll down a bit.

// fx := fx + a[i]*x^(3-i); This statement iteratively adds terms of the polynomial f(x).

Polynomial f(x) has been discussed while discussing polynomialEvaluator function.

// end for; This statement indicates the end of for loop.
Now, this function is complete.

To test this function let us use the class functionTester.

I have made no changes to this function to this class.

Click on Simulate button let me simulate this class by pressing Simulate button in the toolbar.
/* Plotting perspective */ Select z in variables browser.

Note that the value of z remains the same after changes are made to the function.

Let me de-select z and delete the result.

Go back to Modeling perspective Go back to Modeling perspective
Now let me go back to the slides once again.
Slide:

while loop

while loop is used to iterate statements until a given condition is satisfied.

while loop cannot be used in equation section.

for loop is more frequently used in Modelica as compared to while.

Slide:

Arrays

Let us discuss Arrays now.

Arrays are used to represent multi-dimensional data.

They can be constructed using vector notation.

Slide:

Syntax

Syntax for array declaration and indexing is as shown.
Slide:

Problem Statement

To understated more about array construction and indexing.

Let us write a class named matrixAdder which

adds myMatrix and adder matrices to give mySum.

myMatrix and adder matrices are as shown.

Now, let me switch to OMEdit to demonstrate matrixAdder class.

It is already open in OMEdit.

/* Switch to OMEdit */ Click on matrixAdder tab.

Open it in Text view.

parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}; myMatrix is a Real parameter array.
parameter Real[3, 2] myMatrix = {{1,2},{3,4},{5,6}}; Numbers in square bracket represent size of this array.

The size of first dimension is 3.

Similarly, the size of second dimension is 2.

parameter Real[3, 2] myMatrix = // {{1,2},{3,4},{5,6}}; // Highlight piecewise myMatrix array is constructed using three vectors of two elements each.

{1,2} represents the first vector.

{3,4} is the second one and

{5,6}} represents the third vector.

Size of each of this vectors is equal to size of second dimension of this array.

Hence, the size of second dimension of myMatrix is 2.

The number of vectors is equal to the size of first dimension.

Hence, the size of first dimension is equal to 3.

parameter Real[3, 2] adder = {{1,0},{0,1},{1,0}}; adder matrix is constructed in a similar fashion.
To add this two arrays or matrices we need to access elements from two dimensions.

Hence a nested for loop is required.

for i in 1:3 loop This for loop runs through the first dimension.
for j in 1:2 loop Similarly this for loop runs through the second dimension.

Let me scroll down a bit.

mySum[i, j] := myMatrix[i, j] + adder[i, j]; Corresponding elements of myMatrix and adder matrices are added to yield mySum
end for;

end for;

This statements represent the end of each for loop.

The class is now complete.

Click on Simulate button Let me simulate it by clicking on Simulate button.

Close the pop up window if it appears.

/* Plotting perspective */ Let me expand variables column.

Select adder[1,1], myMatrix[1,1], and mySum[1,1].

Note that adder[1,1] plus myMatrix[1,1] gives mySum[1,1] which means that the result is accurate.

Let me de-select them and delete the result.

Let me go back to the slides.
Slide:

Assignment

As an assignment:
  • Write a function named vectorReversal to reverse the order of elements in a vector.
  • Similarly write a function matrixReversal to reverse the order of elements in each row of a matrix.
  • Write functionTester class to test these two functions.
This brings us to the end of this tutorial.
Slide:

About the Spoken Tutorial project

Please watch the video available at following link:

[http://spoken-tutorial.org/ http]://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial

It summarises the Spoken Tutorial project.

Slide:

Spoken Tutorial Workshops

We conducts workshops using spoken tutorials.

Give certificates.

Please contact us.

Slide:

Forum

If you have questions related to this spoken tutorial, please visit the following website.
Slide:

Textbook Companion Project

We coordinate coding of solved examples of popular books.

We give honorarium and certificates to those who do this.

Please visit the following website.

Slide:

Lab Migration Project

We help migrate commercial simulator labs to OpenModelica.

Please visit the following website for more information.

Slide:

Acknowledgements

Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
Slide:

Thanks

We thank the development team of OpenModelica for their support.
Thank you for joining me in this tutorial.

Contributors and Content Editors

Kaushik Datta, Nancyvarkey