Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Help with vector looping and indexing.

Help with vector looping and indexing.

Hello,

I'm trying to create a looping xyz position vector based on a set element value in Dymola. What it does is for example at set value of 6, a vector from point A to B will be divided into 6 parts and joined consecutively from origin to form the whole vector.

What I'm having trouble with is indexing my position vector for the loop. Here's a sample code to help understand :

Code:


parameter Integer n = 6;
parameter Modelica.SIunits.Position r_0(1)[3] = origin+r*e;
parameter Modelica.SIunits.Position r_0(n)[3]
"n represents the number of element";

equation
  for i in 2:n-1 loop
     r_0(i)[3] = r_0(i-1)+r*e
     "i represents the index of current element";
  end for;

I seperated r_0(1) as it starts from origin, but the following postion vector r_0(2:n) will have the same equation (using loop 2 until n-1). The parameter r_0,origin,r and e are of the same size = [3]. What I wanted it to be is just something like this:

Code:


   parameter Modelica.SIunits.Position r_01[3] = origin+r*e;
   parameter Modelica.SIunits.Position r_02[3] = r_01+r*e
   parameter Modelica.SIunits.Position r_03[3] = r_02+r*e
   parameter Modelica.SIunits.Position r_04[3] = r_03+r*e
   parameter Modelica.SIunits.Position r_05[3] = r_04+r*e
   parameter Modelica.SIunits.Position r_06[3] = r_05+r*e

I've been racking my brain on what seems to be a simple problem, any help would be greatly appreciated.

Thank you in advance,
Luqman

p.s. I've been reading https://modelica.org/documents/ModelicaSpec33.pdf but I'm not quite sure I fully understand chapter 10. Sorry to bother if the answer's already in there but some explanation sure would be nice.

Edited by: keybearer - Aug-31-15 23:38:02
There are 0 guests and 0 other users also viewing this topic
You are here: