1 | package TestVectors
|
---|
2 | function f1
|
---|
3 | input Real[:] vIn;
|
---|
4 | input Real[:, :] mIn;
|
---|
5 | output Real[size(mIn, 2)] vOut;
|
---|
6 | algorithm
|
---|
7 | vOut := {1 / (mIn[:, i] * vIn) for i in 1:size(mIn, 2)};
|
---|
8 | end f1;
|
---|
9 |
|
---|
10 | model M1
|
---|
11 | Real[3, 2] m1 = transpose({{1, 2, 3}, {5, 10, 30}});
|
---|
12 | Real[3] v1 = {1, 2, 3};
|
---|
13 | Real[2] y1;
|
---|
14 | algorithm
|
---|
15 | y1 := f1(v1, m1);
|
---|
16 | annotation(
|
---|
17 | experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002),
|
---|
18 | __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian,newInst -d=stateselection --showStructuralAnnotations ");end M1;
|
---|
19 |
|
---|
20 | function f2
|
---|
21 | input Real[:] v1;
|
---|
22 | input Real[:] v2;
|
---|
23 | input Real[:, :] m1;
|
---|
24 | output Real[size(v2, 1)] Xout;
|
---|
25 | protected
|
---|
26 | Real internal;
|
---|
27 | algorithm
|
---|
28 | internal := sum(v2[i] / v1[i] for i in 1:size(v2, 1)) + sum({{m1[i, j] / v1[i] for j in 1:size(m1, 2)} for i in 1:size(m1, 1)});
|
---|
29 | Xout := {v2[i] / (v1[i] * internal) for i in 1:size(v2, 1)};
|
---|
30 | end f2;
|
---|
31 |
|
---|
32 | function f3
|
---|
33 | input Real[:] v1;
|
---|
34 | input Real[:] v2;
|
---|
35 | output Real[size(v2, 1)] out;
|
---|
36 | algorithm
|
---|
37 | for j in 1:size(v2, 1) loop
|
---|
38 | out[j] := (1 - v1[j] - v2[j]);
|
---|
39 | end for;
|
---|
40 | end f3;
|
---|
41 |
|
---|
42 | model M2
|
---|
43 | Real[2] v1 = {0, 0.8};
|
---|
44 | Real[2] v2 = {1, 2};
|
---|
45 | Real[2, 1] m1 = [0.5; 0];
|
---|
46 | Real[2] v3;
|
---|
47 | Real[2] v4;
|
---|
48 | algorithm
|
---|
49 | v3 := f2(v1, v2, m1);
|
---|
50 | v4 := f3(v2, v3);
|
---|
51 | annotation(
|
---|
52 | experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.002),
|
---|
53 | __OpenModelica_commandLineOptions = "--matchingAlgorithm=PFPlusExt --indexReductionMethod=dynamicStateSelection -d=initialization,NLSanalyticJacobian,newInst -d=stateselection --showStructuralAnnotations ");end M2;
|
---|
54 | end TestVectors;
|
---|