Ode45 to solve nonlinear second order ode

Click For Summary
SUMMARY

The discussion focuses on solving a nonlinear second-order ordinary differential equation (ODE) using MATLAB's ode45 function. The equations provided are transformed into three first-order ODEs, with constants A and B set to 10 and 1, respectively. The user encounters errors while implementing the function for ode45 and seeks guidance on correctly using arrays and initial conditions to solve for r and theta simultaneously at t=1. The initial conditions are specified as r(0)=1, theta(0)=0, and (dr/dt)(0)=0.

PREREQUISITES
  • Understanding of nonlinear second-order ordinary differential equations
  • Familiarity with MATLAB and the ode45 solver
  • Knowledge of transforming second-order ODEs into first-order systems
  • Basic concepts of initial conditions in differential equations
NEXT STEPS
  • Review MATLAB documentation on ode45 and its syntax
  • Learn how to convert second-order ODEs into first-order systems
  • Explore examples of solving simultaneous ODEs in MATLAB
  • Practice using arrays in MATLAB for handling multiple variables in ODEs
USEFUL FOR

Students and researchers in mathematics and engineering, particularly those working with differential equations and numerical methods in MATLAB.

sozener1
Messages
19
Reaction score
0

Homework Statement



I'm given two equations

first
(d^2)*r/dt^2 - r((d*theta/dt)^2)= (-A)/r^2 --- this is a non linear second order differential equation

second
(r^2)*((d*theta)/dt)=B

B and A are just constants 1 and 10

from these two equations I obtained three first order odes so that you can use the ode45 in matlab

hopefully you can obtain it as well as its really difficult for me to type the equation with a computer and hopefully you can view the attachments which are the two given equations, for easier viewing
https://www.physicsforums.com/attachments/34339

https://www.physicsforums.com/attachments/34340

I've found d*theta/dt from second equation and substituted it into the first equation and found two first order odes

I have to solve these equations for r when t=1

I'm also given initial conditions r(0)=1, theta(0)=0, (dr/dt)(0)=0

I need to use ode45 in MATLAB to solve this problem and plot it to find r at t=1

and I also need to solve for theta simultaneously using ode45

so far I just getting a whole lot of errors

first of all I wrote a function

and then did something like [t,r]=ode45(@function, timespan, initialcondition) and it just doesn't seem to work out

I know how to use ode45 when I have something like dy/dt=-k*y/t with some initial condition

but with this problem I'm confused I think I'm supposed to use arrays or something

I need to expand my understanding of using ode45 solver so can anyone help me with this??
 
Physics news on Phys.org
Is there not an example in the help files?

One way to start is with a really simple set of equations and get that working, yes you will have to use arrays but this can be figured out with a bit of trial an error.
 

Similar threads

Replies
4
Views
2K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
Replies
12
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
9
Views
2K