# Solving a nonlinear ODE

9 views (last 30 days)
abdullah al - jailawi on 26 Sep 2020
Edited: James Tursa on 26 Sep 2020
Hi all,
I am trying to use Matlab to solve the following equation obtain from the growth of a bubble with a liquid (fluid mechanics) where R is R(t):
R*Rdoubledot + ((3/2)(Rdot)^2) = Pgas/rhoo
With my two initial conditions at t=0 being:
R(t=0) = R0 and Rdot(t=0) = 0
I have basic experience with Matlab, and I only know that I need to use the syntax [t,y] = ode45(odefun , tspan, y0) to solve the given problem.
I would really appreciate any help you guys can offer with this script.
Thank you,
AJ

James Tursa on 26 Sep 2020
Edited: James Tursa on 26 Sep 2020
Step 1: Solve your ODE for the highest order derivative, in this case Rdoubledot (on paper)
Rdoubledot = stuff (you figure this out with simple algebra)
Step 2: Rewrite your ODE as a system of 1st order ODE's (on paper)
In your case you have a 2nd order ODE, so your state vector will be two elements. Call it R:
R(1) = R
R(2) = Rdot
Step 3: FIgure out the equations for the derivatives of Step 3 (on paper)
RDOT(1) = R(2); % this one is easy
RDOT(2) = some expression involving R(1) and R(2) obtained from Step 1 with appropriate substitutions
Step 4: Generate the function handle that you will feed to ode45 (actual code)
odefun = @(t,R) some expression involving t, R(1), R(2)
In this case, the expression needs to be a 2-element column vector using the RDOT stuff from Step 3
Also, the variables Pgas and rhoo will be part of this expression (you need to define them first before generating odefun)
Step 5: Generate the initial condition variable (actual code)
Since you have a two element state, this will be a two element column vector
R0 = [initial R value; initial Rdot value]; % you fill in these values
Step 6: Feed the odefun, R0, and time span to ode45 (actual code)
Give all this a try and come back with any questions you still have. The doc for ode45 gives an example of a 2nd order ODE, so you might look at that.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!