Plotting and Evaluating PROPT Results: Difference between revisions
(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...") |
No edit summary |
||
Line 6: | Line 6: | ||
>> toms t | >> toms t | ||
>> setPhase(tomPhase('p',t,0, | >> setPhase(tomPhase('p',t,0,2*pi,10)) | ||
>> tomStates x y | >> tomStates x y | ||
Line 19: | Line 19: | ||
[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] | |||
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 |
Revision as of 03:41, 19 September 2011
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