How do I use the simulation time as condition in a If statment in a m-File function?
1 view (last 30 days)
Show older comments
Hi,
I using ODE solver to solve my system, in my function I'm using an If statment, but the control statment depends of time. This is the source code:
function o = system(time,x)
global c_sf k_sf k_tf F_sf c_sr k_sr k_tr F_sr m_uf m_ur m_s lf lr z_rf z_rr j_s
z_sf = x(5) - lf * x(7); dz_sf = x(6) - lf * x(8); z_sr = x(5) - lr * x(7); dz_sr = x(6) - lf * x(8);
% Here is my problem
t = timet;
perturbation = 0.08*(1 - cos(8*pi*t))/12;
% z_rf = 0.4*sign(x(2))*sin(x(1));
% z_rr = 0.2*sign(x(4))*sin(x(2));
if t<= 1.25
{
if t<=0.5
{
z_rf = 0;
}
elseif t>=0.75
{
z_rf = 0;
}
else
{
z_rf= perturbation;
}
end
}
elseif t >= 1.5
{
z_rr = 0;
{
else
{
z_rr = 0.08*(1 - cos(8*pi*t))/2;
}
end
O(1) = x(2); O(2) = (-( c_sf*(x(2)-dz_sf) + k_sf*(x(1)-z_sf) + k_tf*(x(1) - z_rf)) -F_sf)/m_uf; O(3) = x(4); O(4) = (-( c_sr*(x(4)-dz_sr) + k_sr*(x(3)-z_sr) + k_tr*(x(3) - z_rr)) -F_sr)/m_ur; O(5) = x(6); O(6) = (-(c_sf*(dz_sf - x(3)) + c_sr*(dz_sr - x(4)) + k_sf*(z_sf - x(1)) + k_sr*(dz_sr - x(3))) + F_sf + F_sr)/m_s; O(7) = x(8); O(8) = (-(c_sf*(dz_sf - x(2))*lf + c_sr*(dz_sr - x(4))*lr + k_sf*(z_sf - x(1))*lf + k_sr*(z_sr - x(3))*lr) - F_sf*lf +F_sr*lr)/j_s;
o=[O(1); O(2); O(3); O(4); O(5); O(6); O(7); O(8)];
I use another M-file to run my program an to configurate the ODE solver. But when I used the ODE there is a mistake in the if statement. How do I implement the time simulation in the function? Help me!
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!