>
|
|
Assign model the filename of the MapleSim model we want to analyze.
>
|
|
Use MapleSim[LinkModel] to link to the MapleSim model.
>
|
|
Inspect the available parameters.
>
|
|
| (1) |
Use the GetCompiledProc export of A to assign the module that will be passed to MonteCarlo. Assign nominal values for the two model parameters of interest.
>
|
|
Assign a simple procedure that generates a random variable uniformly distributed around a nominal value.
>
|
|
Call MonteCarlo, using C1 and assigning random variables for the L and C model parameters. The C_opts option specifies that the final time of the simulation is 0.5 seconds. The include_nominal option means the first simulation corresponds to the given nominal values of the model parameters. The num_sims option specifies that 100 randomized simulations are made.
>
|
|
Verify that the values of the parameters for the first simulation are the nominal values. The subexpression results[1] accesses the first element of the list results. That element is a record. The full expression results[1]:-params specifies the params field of that record. The params field, as seen below, is a set of equations that express the sampled values of the parameters.
Display the data for the final two sample times for the first (nominal) simulation. The notation results[1] accesses the first record stored in the list results; results[1]:-data references the data field (a Matrix) in that record; the [-2..-1,..] indices extract a sub-block of the Matrix (the last two rows, all columns), see rtable_indexing.
>
|
results[1]:-data[-2..-1,..];
|
| (3) |
The first column is the time, the remaining column(s) corresponds to the output(s) of C1:
Plot the output versus time for all records. To do that, generate a set of two-column matrices, the first column being the time, the second being the output of interest. The seq command is used to sequentially access the Matrices in results. The expression rec:-data[..,[1,2]] corresponds to the appropriate sub-block of the Matrix in the data field; in this case, all rows (..) and the first and second columns, ([1,2]). Because each Matrix is already two-columns, we could have used the simpler notation rec:-data, however, if the system has more than one output (probe), we would then use the notation rec:-data[..,[1,k]], where k is the column of interest.
>
|
plot({seq(rec:-data[..,[1,2]], rec=results)});
|
Generate a histogram of the final output point by creating a Vector of the data and passing it to Statistics[Histogram]. The expression rec:-data[-1,2] evaluates to the final row (-1), second column, of the data Matrix of a record in the results list.
>
|
X := Vector([seq(rec:-data[-1,2], rec=results)]):
|
| |
|
Assigning an Objective Procedure
|
|
•
|
The module returned by GetCompiledProc has a SetObjective export that uses a provided procedure to manipulate the output. Here we pass it a procedure to square the output (column two of the matrix).
|
>
|
C1:-SetObjective( proc(M)
local i;
for i to upperbound(M,1) do
M[i,2] := M[i,2]^2;
end do;
M;
end proc):
|
•
|
Run a MonteCarlo analysis with the squared output.
|
>
|
|
>
|
plot({seq(rec:-data[..,[1,2]], rec=results2)});
|
•
|
The objective procedure is not limited to modifying the matrix of simulation data, it can also compute a value from the matrix and return that. Here we assign a procedure that returns the peak of the squared result.
|
>
|
C1:-SetObjective(proc(M) max(map(x->x^2, M[..,2])) end proc):
|
•
|
Run a MonteCarlo analysis; use the ret_record option to return a record.
|
>
|
|
•
|
Compute the range over which the peak value varied.
|
>
|
|
|