Ode45 to solve nonlinear second order ode

In summary, the conversation discusses a problem involving two equations, one being a non-linear second order differential equation and the other being a first order differential equation. The goal is to obtain three first order ODEs and use ode45 in MATLAB to solve for r and theta at t=1. The initial conditions and function are provided, but the individual is having trouble getting the solver to work. They mention needing to use arrays and expanding their understanding of ode45.
  • #1
sozener1
19
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
  • #2
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.
 

Related to Ode45 to solve nonlinear second order ode

1. What is Ode45 and how does it solve nonlinear second order ODEs?

Ode45 is a numerical method used to solve ordinary differential equations (ODEs). It uses a combination of fourth and fifth order Runge-Kutta methods to approximate the solution of the ODE. It is particularly useful for solving nonlinear second order ODEs because it can handle a wide range of initial conditions and provides a more accurate solution compared to other methods.

2. How do I use Ode45 to solve a nonlinear second order ODE in MATLAB?

To use Ode45 in MATLAB, you need to define a function that represents the ODE. This function should take in the independent variable, the dependent variable, and any other parameters as inputs and return the value of the derivative at that point. Then, you can call the Ode45 function with the defined function, the desired time span, and the initial conditions as inputs. Ode45 will then return the solution of the ODE at the specified time points.

3. Can Ode45 handle stiff equations?

Yes, Ode45 can handle stiff equations. It uses a variable step size to adapt to the stiffness of the equation and ensure accuracy. However, for highly stiff equations, it is recommended to use a stiff solver such as Ode15s or Ode23s.

4. What are the advantages of using Ode45 to solve nonlinear second order ODEs?

Ode45 has several advantages for solving nonlinear second order ODEs. It is a robust and efficient method that can handle a wide range of initial conditions. It also provides a more accurate solution compared to other methods, especially for stiff equations. Additionally, Ode45 is readily available in MATLAB, making it easily accessible to users.

5. How do I know if the solution obtained from Ode45 is accurate?

Ode45 uses a variable step size to ensure accuracy of the solution. However, it is always recommended to check the solution by plotting it and comparing it to known solutions or using a different method to solve the same equation. Additionally, you can adjust the tolerance levels in Ode45 to improve the accuracy of the solution if needed.

Similar threads

Replies
4
Views
570
  • Calculus and Beyond Homework Help
Replies
3
Views
405
  • Calculus and Beyond Homework Help
Replies
2
Views
243
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
14
Views
490
  • Calculus and Beyond Homework Help
Replies
16
Views
623
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
612
  • Calculus and Beyond Homework Help
Replies
9
Views
1K
Back
Top