Tutorial: ODE-IVP
Part 1: 1st order ODE-IVP problem
Download the MATLAB tutorial source file
Download the C-prog source file
Problem
Solve for the response (Vout) of an RC circuit with a sinusoidal input (Vin), from t=0 to 0.1 sec.
where RC=tau=0.01; T=1/tau; f=100; Vm=1; w=2pif;


Tutorial: MATLAB
MATLAB : ode45()
Lets define the RC circuit ODE function f(t,v) as gradFunc_RC(t,v).
Analytical Solution (Ground-truth)
The true analytical solution can be expressed as

Exercise
Exercise 1-1: Euler's Explicit Method ( MATLAB)
Exercise 1-2: Euler's Explicit Method ( C-Prog)
Create a project under
\tutorial\Tutorial_ODE\Use the C-prog source template : Assigment_ODE_student.cpp
Fill-in the blanks
Exercise 2: Euler's Modified Method (MATLAB)

Create odeEM_student.m
Modify the given template code
Exercise 3-1: 2nd Order Runge-Kutta (MATLAB)

Let alpha=1, C1=0.5, C2=0.5.
Modify the given template code:\
Exercise 3-1: 2nd Order Runge-Kutta ( C-Prog)
Fill-in the blanks
Part 2: Higher-order ODE-IVP
Download the tutorial source file
Problem
Solve for the response of the given system:


Let, m=1; k=6.9; c=7; f=5; u(t)=Fin(t)=2cos(2pift)
Tutorial: MATLAB
Lets define the mck ODE functions as gradFunc_mck(t, vecY).

gradFunc_mck.m
MATLAB : ode45()
Exercise
Exercise 1: Euler's Explicit Method for 2nd-order ODE (MATLAB)
sys2EU_student.m
First, fill-in this blank and complete the algorithm
Then, create the function file as sys2EU_student.m
[t, yE, vE] = sys2EU_student(@gradFunc_mck,a,b,h,yINI, vINI);
Exercise 2-1: 2nd order Runge-Kutta for 2nd-order ODE (MATLAB)
Create sys2RK2_student.m
Modify the given template code
Exercise 2-2: 2nd order Runge-Kutta for 2nd-order ODE (C-Prog)
Fill-in this blank and complete the algorithm
Assignment
Q1. Create C/C++ function for 1st order ODE
Use 2nd, 3rd order Runge-Kutta method
For RK2, use alpha=1, C1=0.5
For RK3, use classical third-order Runge-Kutta
Q2. Create C/C++ function for 2nd order ODE
Use 2nd order Runge-Kutta method
Last updated
Was this helpful?