MATLAB: Differentiation for timing input

differentiation for timing input

I want to differentiate these equation with matlab.I use input v1 as constant 1 and for input v2 use signal builder for ( time 1 to 4 input 0;time 4 to 6 input 1,time 6 to 10 input 0).please help me.
x1dot=v1*sin(x3);
x2dot=v1*cos(x3);
x3dot=v2;

Best Answer

This is a system of ODE. You can use ode45() to find a solution
tspan = [0 10];
IC = [0; 0; 0]; % initial condition
[t, X] = ode45(@odeFun, tspan, IC);
plot(t, X);
legend({'x1', 'x2', 'x3'}, 'FontSize', 16);
function xdot = odeFun(t, x)
v1 = 1;
if t < 4
v2 = 0;
elseif t < 6
v2 = 1;
else
v2 = 0;
end
x3 = x(3);
x1dot=v1*sin(x3);
x2dot=v1*cos(x3);
x3dot=v2;
xdot = [x1dot; x2dot; x3dot];
end