Plotting and Evaluating PROPT Results

From TomWiki
Revision as of 03:41, 19 September 2011 by Per (talk | contribs)
Jump to navigationJump to search

After solving a problem with PROPT, you will probably want to evaluate and/or plot the results.

In PROPT, state and control variables (tomStates and tomControls) are functions of a set of coefficients, and of time.

For example, let's create a couple of states:

>> toms t
>> setPhase(tomPhase('p',t,0,2*pi,10))
>> tomStates x y

We can see how x is constructed by converting it into m-code:

>> [code, tempD] = mcode(x)
 
code =
 out      = interp1p(tempD{1},x_p,t);
 
tempD = 
   [11x1 double]

So x depends on time t and on the coefficient vector x_p. When solving for x in a set of ODE:s or DAE:s, we are actually solving for the coefficients x_p.

For example, we can solve a simple set of ODE:s like this:

>> solution = ezsolve(0,{collocate({dot(x)==y,dot(y)==-x}),initial({x==1,y==0})})
solution = 
   x_p: [11x1 double]
   y_p: [11x1 double]

Once we have a solution, we can substitute that into any symbolic expression. For example:

>> x_sol = subs(x,solution)
>> mcode(x_sol)

ans =
 out      = interp1p(tempD{2},tempD{1},t);

Now, x_sol is a symbolic expression that only depends on t. If we substitute in a numeric value for t, then we get a numeric result:

>> subs(x_sol,t==0.2)

ans =
   0.9801