Solving a differential equation numerically (in Octave, Matlab &c.)

In summary, the individual is seeking help with solving a second-order non-linear differential equation by decomposing it into a system of two first-order equations. They are using GNU Octave to provide a numerical approximation and are looking for assistance in creating the program. They also share a tutorial they found helpful for solving similar problems.
  • #1
ejlflop
2
0

Homework Statement



I have a second-order non-linear differential equation that I am trying to solve. So far I have decomposed it into a system of 2 first-order equations, and have (possibly) determined that it cannot be solved analytically. So I am trying to do a nice numerical approximation using GNU Octave (basically compatible with Matlab, so if you can do it with Matlab please can you help too :-D).

Octave needs the equation expressed as first-order DEs -- which I think I've done -- I'm just not sure how to go about doing the actual approximation.


Homework Equations



Original second-order DE:
[tex]\frac{d^2 \theta}{dt^2} + \frac{k}{m}\cdot\frac{d\theta}{dt} - g\cdot\sin\theta = 0[/tex]

Note that [tex]k, m, g[/tex] are arbitrary constants (yes, [tex]g[/tex] is 9.81!)

The Attempt at a Solution



Substitute:
[tex]\frac{d\theta}{dt} = w[/tex]

Hence:

[tex]\frac{d^2 \theta}{dt^2} = w\frac{dw}{d\theta}[/tex]

[tex]w\frac{dw}{d\theta} + (\frac{k}{m}\cdot w) - (g\cdot\sin\theta) = 0[/tex]

Attempt at Octave program to approximate it a bit:

Code:
function wdot = f (w, theta)
  g = 9.8
  k = 1
  m = 0.1
  wdot = (g*sin(theta) - (k/m)*w)/w
endfunction

theta = linspace(0, 20, 400);
y = lsode ("f", 1, theta);
plot (y, theta);

So this gives me a nice little graph, but obviously it's not a total solution -- that would involve computing the whole system of 2 DEs, which is what I don't know how to do!
Any help much appreciated, thanks.
 
Physics news on Phys.org
  • #2
No worries; I found a nice tutorial on how to do it in matlab, and adapted it for my own purposes.
If anyone has a similar problem, see this youtube video, it's very good:
https://www.youtube.com/watch?v=http://www.youtube.com/watch?v=fx3bl4oA_0U
 

Related to Solving a differential equation numerically (in Octave, Matlab &c.)

What are differential equations?

Differential equations are mathematical equations that describe how one or more variables change over time. They are used to model many real-world phenomena, such as population growth, radioactive decay, and motion of objects.

Why do we need to solve differential equations numerically?

Some differential equations cannot be solved analytically, meaning there is no exact formula for the solution. In these cases, numerical methods are used to approximate the solution and provide useful insights into the behavior of the system.

What is Octave and Matlab?

Octave and Matlab are programming languages and software tools commonly used in scientific computing. They are particularly useful for solving differential equations numerically due to their extensive libraries and built-in functions.

What are the steps for solving a differential equation numerically?

The general steps for solving a differential equation numerically are:

  1. Convert the differential equation into its equivalent system of first-order differential equations.
  2. Choose an appropriate numerical method, such as Euler's method or Runge-Kutta methods.
  3. Discretize the time interval and solve the system of equations at each time point using the chosen method.
  4. Repeat the previous step until the desired accuracy is achieved.

What are some common challenges when solving differential equations numerically?

Some common challenges when solving differential equations numerically include:

  • Choosing an appropriate numerical method for the specific problem.
  • Ensuring the numerical solution is accurate and stable.
  • Dealing with stiff systems, where the solution changes rapidly over a short time interval.
  • Selecting appropriate initial conditions and time intervals.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
737
  • Calculus and Beyond Homework Help
Replies
6
Views
554
  • Calculus and Beyond Homework Help
Replies
1
Views
974
  • Calculus and Beyond Homework Help
Replies
7
Views
535
  • Calculus and Beyond Homework Help
Replies
21
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
360
  • Calculus and Beyond Homework Help
Replies
2
Views
711
  • Calculus and Beyond Homework Help
Replies
18
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
1K
Replies
7
Views
688
Back
Top