Challenge

Week 3 - Solving second order ODEs

The program is generated according to the challenge given .

The ODE is solved as per the challenge and the animation is made for the pendulum damping according tom the given input provided

where

L= 1m

m= 1kg

b=0.05

g= 9.81m/s^2

angular velocity =3rad/sec

angular displacement = 0

for solving we have to call the ODE fn so we have created another program for solving and called it to the pendulum fn and program is stimulated according to the input provided in the challenge and executed the function and animation of the pendulum is saved as avi format with the help of movie comment and is stored.I am attaching the program file and the animation video along with this.

clear all
close all
clc


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

%inital condtion
theta_0 =[0;3];

ct = 1;
%time points
t_span = linspace(0,10,100);

%solve ODE
[t,result] = ode45(@(t,theta) ode_func(t, theta, b,g,l,m),t_span, theta_0);
angle = result(:,2)
    for i = 1:length(angle)
    ANGLE = angle(i)
    x0 = 5
    y0 = 5
    x1 = x0+ l*sin(ANGLE)
    y1 = y0-l*cos(ANGLE)
    
    figure(1)
    plot([x0 x1],[y0 y1],'linewidth',2,'color','b')
    hold on
    plot(x1,y1,'o','MarkerFacecolor','r')
    axis([3.5 6.5 3.5 6.5])
    hold off
    
    end
   
    
%     pause(0.03)
%     ct = ct+1;
%     M(ct) = getframe(gcf);

%     movie(M)
%     videofile = Videowriter('pendulum.avi','Uncompressed AVI');
%     open(videofile)
%     writeVideo(videofile,M)
%     close(videofile)

I am attaching the program for calling fn for solving ODE eq also alongb with this

function [dtheta_dt] = ode_func(t,theta,b,g,l,m)

theta1 = theta(1)
theta2 = theta(2)
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1);
dtheta_dt = [dtheta1_dt;dtheta2_dt];
end

Red line indicate velocity and blue line indicate displacmet

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.