Challenge

Week 3 - Solving second order ODEs

clc;
clear all;

m= 1;
b= 0.1;
l=0.5;
g=9.81;

r=g/l;
k=b/(m*l);

f = @(t,x) [x(2); -k*x(2) - r*sin(x(1))];


init=[pi/2;0];

[t,x] = ode45(f,[0 20],init);


%animation origin
o = [0 0];
axis(gca,'equal');% aspect raio of plot
axis([-0.7 0.7 -0.7 0.2]);
grid on;

%loop for animation

for i=1:length(t)
p =l*[sin(x(i,1)) -cos(x(i,1))];



pend= line([o(1) p(1)],[o(2) p(2)]);


pause(0.001);


end

% sorry for animation and plotting of ball

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.