how to plot control input from ode45
显示 更早的评论
I'm trying to solve a nonlinear differential equation using ode45 I have a nonlinear system in the following form x = A*x + B*u and u is a function of the states x. Here is my function file,
function xprime = myode(t, x)
global g hs m S Cd Cl r0 rho0 h u
L = 0.5*rho0*exp(-(x(1)-r0)/hs)*x(3)^2*S*Cl/m;
f1 = x(3)*sin(x(6));
f2 = x(5);
f3 = -x(2) - g*sin(x(6));
f4 = x(3)*cos(x(6));
f5 = -x(5)*x(3)*sin(x(6))/hs + x(2)*(x(2) + g*sin(x(6)))*sin(x(6))/hs +...
x(2)*cos(x(6))^2*(g-x(3)^2/x(1))/hs -...
2*x(5)*(x(2) + g*sin(x(6)))/x(3) -2*x(2)*(x(2) +...
g*sin(x(6)))^2/x(3)^2 - 2*x(2)*x(5)/x(3) +...
2*x(2)*g*cos(x(6))^2*(g-x(3)^2/x(1))/x(3)^2;
f6 = -(g-x(3)^2/x(1))*cos(x(6))/x(3);
x2r = -.1221*t.^2 + 5.9859*t - 5.7866;
x5r = -.2442*t + 5.9859;
x2rdot = x5r;
x5rdot = -.2442;
x2rddot = x5rdot;
w1 = -x(2)*cos(x(6))*(1/hs + 2*g/x(3)^2)*L;
w2 = -x(2)*cos(x(6))*(1/hs + 2*g/x(3)^2)*L;
W = [w1;w2];
Delta = [h^2/2 0;0 h];
e1 = x(2) - x2r;
e2 = x(5) - x5r;
e = [e1;e2];
z1 = h*x(5) + (h^2/2)*f5;
z2 = h*f5;
z = [z1;z2];
d1 = h*x2rdot + h^2/2*x2rddot;
d2 = h*x5rdot;
d = [d1;d2];
u = -((Delta*W)'*Delta*W)^(-1)*(Delta*W)'*(e + z - d);
if( abs(u) > 1 ) %limits on control input
u = sign(u);
end
xprime = zeros(6,1);
xprime(1) = f1;
xprime(2) = f2;
xprime(3) = f3;
xprime(4) = f4;
xprime(5) = f5 -x(2)*cos(x(6))*(1/hs + 2*g/x(3)^2)*L*u;
xprime(6) = f6 + L*u/x(3);
When I go to my main function file I can easily plot my states by using the command
plot(t,x(:,1)
plot(t,x(:,2)
.
.
.
plot(t,x(:,n))
and so on for n states. Since u is a function of these states I could plot u, i.e, u = blahblah(x(:,1),x(:,2),...,x(:,3)) and use the command plot(t,u)
However, my control input in this case is really long and complex and rewriting my control input in terms of my numerical answers x(:,n) seems time-consuming. Is there an easier way to plot my control input without having to rewrite the whole thing in my main function file? Any help is appreciated. Thanks.
回答(3 个)
Walter Roberson
2011-9-5
0 个投票
I am not clear as to what your control input is for this case ?
The built in ways for easier plotting are through the options structure; see in particular http://www.mathworks.com/help/techdoc/ref/odeset.html#f92-1016858 and read down at least as far as the mention of odeplot()
C
2011-9-6
1 个评论
Walter Roberson
2011-9-6
Each plot() call is drawing a new plot overwriting the previous one. You only see the final one because you never give permission to MATLAB to draw the others. Add a drawnow() call after the plot() call to be able to see the intermediate ones, and have a look at the documentation for "hold on"
C
2011-9-6
0 个投票
4 个评论
Walter Roberson
2011-9-6
Sorry, I have never tried that kind of plotting.
Bilal sadiq
2018-7-17
Is any one there who can solve this problem for me ?
Walter Roberson
2018-7-17
Bilal sadiq, please clarify what problem it is that you are trying to solve?
Sunil Ojwani
2018-12-30
bilal sadiq , have you got your answer ??? i have same problem regarding control input plot from ode45
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!