Plotting and Evaluating PROPT Results: Difference between revisions

From TomWiki
Jump to navigationJump to search
(Created page with "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 o...")
 
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:


In PROPT, state and control variables (tomStates and tomControls) are functions of a set of coefficients, and of time.
In PROPT, state and control variables (tomStates and tomControls) are functions of a set of coefficients, and of time.
When numeric values are given for the coefficients and for time, states and controls get numeric values.
== Example ==


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


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


Line 19: Line 22:
     [11x1 double]
     [11x1 double]


So <tt>x</tt> depends on time <tt>t</tt> and on the coefficient vector <tt>x_p</tt>
So <tt>x</tt> depends on time <tt>t</tt> and on the coefficient vector <tt>x_p</tt>.
When solving for <tt>x</tt> in a set of ODE:s or DAE:s,
we are actually solving for the coefficients <tt>x_p</tt>.
 
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]
 
(Note that the solution does not contain values for <tt>t</tt>. That is because t is not an unknown <tt>t</tt>.)
 
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, <tt>x_sol</tt> is a symbolic expression that only depends on <tt>t</tt>. If we substitute in
a numeric value for <tt>t</tt>, then we get a numeric result:
 
>> subs(x_sol,t==0.2)
ans =
    0.9801
 
It is possible to substitute in a vector of values, one at a time, using <tt>atPoints</tt>
 
>> atPoints(1:6,x_sol)
 
ans =
    0.1153
  -0.8754
  -1.0613
  -0.2714
    0.7680
    1.1013
 
Some common substitutions have shortcuts, for example <tt>initial(x_sol)</tt> sets <tt>t</tt> to the inital
point on the active tomPhase, and <tt>collocate(x_sol)</tt> uses the collocation points.
 
The command <tt>collocate(t)</tt> returns a list of the collocation points.
 
In order to plot a tomState, one can of course use atPoints to create a vector of values to plot, but there
is also a short-cut, called <tt>ezplot</tt>. As soon as the solution has been computed we can do:
 
>> ezplot([x,y])
 
[[Category: PROPT]]

Latest revision as of 10:48, 29 February 2012

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. When numeric values are given for the coefficients and for time, states and controls get numeric values.

Example

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]

(Note that the solution does not contain values for t. That is because t is not an unknown t.)

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

It is possible to substitute in a vector of values, one at a time, using atPoints

>> atPoints(1:6,x_sol)

ans =
   0.1153
  -0.8754
  -1.0613
  -0.2714
   0.7680
   1.1013

Some common substitutions have shortcuts, for example initial(x_sol) sets t to the inital point on the active tomPhase, and collocate(x_sol) uses the collocation points.

The command collocate(t) returns a list of the collocation points.

In order to plot a tomState, one can of course use atPoints to create a vector of values to plot, but there is also a short-cut, called ezplot. As soon as the solution has been computed we can do:

>> ezplot([x,y])