# ode45

7 views (last 30 days)
Villanova on 10 Dec 2011
I am trying to use ODE45. I am just wondering why my plots are just constant lines. Is it possible if anyone could kindly help me out. Those parameters that I have are purely made up, since there is no way to come up with them at this moment because I am not doing System Identification. I did my best to guess them correctly, but I didn't have much luck. Thanks. The first code is:
function xdot=bond_boat(t,x)
global vr L R T G vl B tp vw Ry m mu Q vwdot Rx K Rtheta Jp J
xdot(1,1)=(vr/L)-(R/L)*x(1)-((T*G)/(2*L))*(x(4)+x(5));
xdot(2,1)= (vl/L)-(R/L)*x(2)-((T*G)/(2*L))*(x(4)-x(5));
xdot(3,1)= -1/(2*B)*(tp^2*x(5)*x(4)+ 2*tp*vw*x(5)) - Ry/m;
xdot(4,1) = ((T*G)/Q)*x(4) -((mu*tp)/Q)*(m*vwdot - (m*tp/B)*x(3)*x(5) - Rx);
xdot(5,1) = ((T*G)/K)*x(5)- ((mu*tp)/(B*K))*(m*x(3)*(tp*x(4) + 2*vw) + 2*Rtheta);
and the second code is as the following clc close all clear all
global vr L R T G vl B tp vw Ry m mu Q vwdot Rx K Rtheta Jp J
vr = .03;
L= 10;
G = 6;
vl = .03;
B = 0.1;
T = (B/2)*(.001);
tp = 10;
vw = .01 ;
Ry = .2 ;
m = 1.34;
mu = .1;
vwdot = 0 ;
Rx = .2;
Rtheta= .2 ;
Jp = .1;
Q = Jp + .5*mu*(tp^2)*m;
J = .03;
K = Jp + (2*mu*(tp^2)* J/(B^2));
R = 2;
ic=[0.1;10;.01;1;0] ;
time = [0 10];
[t,x] = ode45('bond_boat', time, ic);
subplot(5,1,1);
plot(t,x(1),'red')
xlabel('Time');
ylabel('X_1');
subplot(5,1,2);
plot(t,x(2),'blue')
xlabel('Time');
ylabel('X_2');
subplot(5,1,3);
plot(t,x(3),'red')
xlabel('Time');
ylabel('X_3');
subplot(5,1,4);
plot(t,x(2),'blue')
xlabel('Time');
ylabel('X_{4new}');
subplot(5,1,5);
plot(t,x(5),'red')
xlabel('Time');
ylabel('X_{5new}');

Mohsen Davarynejad on 10 Dec 2011
The only thing you have to do is to change
plot(t,x(1),'red')
to
plot(t,x(:,1),'red')
and so on for the rest of plots. The rest of the code is not optimial, but its ok. To do a better job, you could pass the global variables to the ode45 as an input argument.
Villanova on 11 Dec 2011
Merc Mohsen Jan, kheyli lotf kardi. Mesl inke shoma ham eyn e man control kar mikonid :)
Mohsen Davarynejad on 11 Dec 2011
Salam Farshad, Khahesh mikonam. Na rastesh, man Control kar boodam :), valy alan bishtar Computer science hastam.