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

Click For Summary
The discussion focuses on solving a second-order non-linear differential equation numerically using GNU Octave, after determining that an analytical solution is not feasible. The user has successfully decomposed the equation into a system of two first-order equations and is seeking guidance on how to perform numerical approximations. They provide a sample Octave function intended to compute the derivatives but acknowledge that it does not fully solve the system. The user also shares a helpful tutorial they found for Matlab that they adapted for their needs. Overall, the thread highlights the challenges of numerical methods in differential equations and the importance of community resources for problem-solving.
ejlflop
Messages
2
Reaction score
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:
\frac{d^2 \theta}{dt^2} + \frac{k}{m}\cdot\frac{d\theta}{dt} - g\cdot\sin\theta = 0

Note that k, m, g are arbitrary constants (yes, g is 9.81!)

The Attempt at a Solution



Substitute:
\frac{d\theta}{dt} = w

Hence:

\frac{d^2 \theta}{dt^2} = w\frac{dw}{d\theta}

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

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
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
 
Question: A clock's minute hand has length 4 and its hour hand has length 3. What is the distance between the tips at the moment when it is increasing most rapidly?(Putnam Exam Question) Answer: Making assumption that both the hands moves at constant angular velocities, the answer is ## \sqrt{7} .## But don't you think this assumption is somewhat doubtful and wrong?

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
2K