0

enter image description here

enter image description here

I made my code like this,

function DK = pendulum_cartesian(t,K)    
g = 9.8; l = sqrt(K(1)^2 + K(2)^2);  
DK = zeros(4,1);
DK(1) = K(3);
DK(2) = K(4);
DK(3) = ( (-K(1)*K(3)^2) - (K(1)*K(4)^2) + K(1)*K(2)*g )/(l^2);
DK(4) = ( (-K(2)*K(3)^2) - (K(2)*K(4)^2) - (K(1)^2)*g )/(l^2);

theta = atan(K(2)/K(1));

plot(t,theta);

end

and i typed,

[t,K] = ode45(@pendulum_cartesian, [0,10], [0.1,0.00017,0.1,0])

but there is no value in theta, and plots nothing.

where is a problem?

1 Answers1

0

Assuming your equations and your code is correct.

This is what I used for the function:

function DK = pendulum_cartesian(t,K)    
DK = zeros(4,1);
DK(1) = K(3);
DK(2) = K(4);
DK(3) = ( (-K(1)*K(3)^2) - (K(1)*K(4)^2) + K(1)*K(2)*9.81 )/(K(1)^2 + K(2)^2);
DK(4) = ( (-K(2)*K(3)^2) - (K(2)*K(4)^2) - (K(1)^2)*9.81 )/(K(1)^2 + K(2)^2);
end

Then run with:

[t,K] = ode45(@pendulum_cartesian, [0,10], [0.1;0.00017;0.1;0]);
theta = atan(K(:,2)/K(:,1));
plot(t,theta);
MrYouMath
  • 1,036
  • 6
  • 17