Challenge

Week 3 - Solving second order ODEs

clear all
close all
clc

%inputs

b=0.05;
m=0.1;
g=9.81;
L=1;
theta_0=[0;3];
t_span=linspace(0,20,300);

%to solve the 2ODE using in built functin ode45
[t, result] = ode45(@(t,theta) ode_fun(t,theta,b,m,g,L),t_span,theta_0);

Theta=result(:,1);
Time= t_span;

ct=1;
for i=1:length(Theta)
    Angle1=Theta(i); 
    %below 3 line of the program are created to run time for each angle of theta
    j=1:length(Time)
    T1=Time(j)
    b=sprintf('Time=%fs%',T1)
% x,y are the fixed end of pendulum
    x=0;
    y=0;
    %Using theta , the value of x1&y1 are found which is the swing end of penulum
    x1=L*sin(Angle1)
    y1=-L*cos(Angle1)
    
    %ploting the graph with the x1, and y1
    
    plot([x x1],[y y1],'linewidth',0.5,'color' ,'r')
    % Programed to show the time for each angle of pendulum but its not
    % working
    text(0,0.6,b)
    hold on
    %marker comman is used to shown the sphere
    plot([x1],[y1],'-o','MarkerSize',10,'markerfacecolor','c','markeredgecolor','c')
    axis([-1.1 1 -1.1 1]);
    
    hold off
    pause (0.001)
    M(ct)=getframe(gcf)
    ct=ct+1;         
  end
%Animation is uploaded in you tube 'https://youtu.be/h1Q_OEV5QBA'
Movie=(M)
Videofile=VideoWriter('Simple_pendulum.avi','Uncompressed AVI')
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)

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.