Challenge

Week 4.1 - Solving second order ODEs

Report on Solving second order ODEs

Aim:

  • To write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping

  • To animate the motion of the pendulum, as shown in the below figure.

Software used: MATLAB

Code:

ODE Function code:

Explanation:

  • b introduces damping, causing the pendulum to slow down over time.
  • The pendulum starts from the vertical position (0 radians) with an initial angular velocity of 3 rad/s.
  • Creates 500 time points from t=0 to t=10.
  • Calls ode45 to solve the pendulum equations.
  • Uses the anonymous function @(t,theta) ode_func(...) to pass parameters.
  • Plot the graph between Angular displacement vs. time and Angular velocity vs. time.
  • For loop is used to animate the pendulum each time.
  • (x0, y0) is the fixed pivot point and (x1, y1) is the pendulum bob position.
  • line 34 plots the pendulum bob as a red circle.
  • line 37 draws the pendulum rod.
  • line 38 adds a pivot bar for reference.

Result:

Conclusion:

  • The ODE is solved.
  • You tube link for an animation - https://youtu.be/otK2GUVfO1M .

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.