-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.m
More file actions
46 lines (35 loc) · 1.67 KB
/
Copy pathExample.m
File metadata and controls
46 lines (35 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
%% === MethodScope Usage Example ===
%Here we have a p-coded file, PM_dX_Peltier.p, used in the calculatation of
%the derivatives of a Peltier cell space-state model. It takes two
%arguments: i) A vector of three elements representing the three states of
%the system, ii) A scalar representing the input voltage, ranging from 0 to
%6.
%We can declare a state and input...
state = [10 20 30]';
input = 6;
%...and pass them to the function to get the derivatives
result = PM_dX_Peltier(state, input);
fprintf('The derivatives for the given input are: %s\n', mat2str(result));
%However, as the system is of black-box nature, we have no immediate way to
%know how these values were generated...
% == Enter MethodScope! ==
%We first declare a bypasser of operations to be used later...
bypasser = OperationBypasser();
%...and then two MethodScope instances with the same values as the state
%and input used previously
state = MethodScope(state, bypasser);
input = MethodScope(input, bypasser);
%Both arguments can be passed normally to the function, and will return
%instances of themselves instead of numerical values
result = PM_dX_Peltier(state, input);
%Indexing bypassing is now disabled in order to access the different values
%on the result vector
bypasser.Indexing = true;
%The operation trees are extracted from the MethodScope instances
trees = arrayfun(@(x) x.OperationTree, result);
%Finally, they're passed to a OperationPresenter for better visualization
presenter = OperationPresenter(trees);
presenter.present();
%It is now possible to extract the three equations that govern the
%derivative update portion of the system, and how they relate to each of
%the input passed as argument!