Hi Cristina
It depends a bit on how your torque and force trajectories are defined, but the easiest way in my opinion: If torque and force are functions of (t,theta) as well, then simply write two functions, e.g. tau = compute_torque(t,theta) and f = compute_force(t,theta), and replace the expressions in your leg function, i.e.
function tau = compute_torque(t,theta)
tau = (1-exp(-t^2);
end
function f = compute_force(t,theta)
f = sin(t)*theta(2);
end
function [ dtheta ] = leg( t,theta)
m=1;
g=9.8;
tau=compute_torque(t,theta);
f=compute_force(t,theta);
k=500;
r0=0.01;
dtheta=zeros(2,1);
dtheta(1)=theta(2);
dtheta(2)=tau/m+g*sin(theta(1))*( (f - m*g*cos(theta(1)))/k +r0 );
end
All clear?
Best Answer