Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11386 > unrolled thread
| Started by | Nick Broderick <crazychessman@msn.com> |
|---|---|
| First post | 2012-08-17 07:44 +0000 |
| Last post | 2012-08-18 07:44 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
NDSolve bug? Nick Broderick <crazychessman@msn.com> - 2012-08-17 07:44 +0000
Re: NDSolve bug? DC <b.gatessucks@gmail.com> - 2012-08-18 07:44 +0000
| From | Nick Broderick <crazychessman@msn.com> |
|---|---|
| Date | 2012-08-17 07:44 +0000 |
| Subject | NDSolve bug? |
| Message-ID | <k0ksom$66f$1@smc.vnet.net> |
I am using NDSolve to simulate the motion of a particle under linear drag and constant acceleration directed such that the particle is always forced back towards the origin. There are two drag constants: one is applied when the particle moves back towards centre, the other when it is moving away from the origin. The particle experiences no acceleration or drag when it sits precisely on the origin. This creates five subcases in my equation of motion. (g, b and c are always positive, x0 and v0 are initial position and velocity, respectively.)
sol =
First[x /.
NDSolve[{x''[t] ==
Piecewise[{{-g - b*x'[t],
x[t] > 0 && x'[t] > 0}, {-g - c*x'[t],
x[t] > 0 && x'[t] <= 0}, {g - b*x'[t],
x[t] <= 0 && x'[t] <= 0}, {g - c*x'[t],
x[t] <= 0 && x'[t] > 0}}, 0], x'[0] == v0,
x[0] == x0}, x, {t, 0, T}, MaxSteps -> \[Infinity],
AccuracyGoal -> 3]];
In most cases for the calculation is fine. But when I try the special case x0=0 and v0=0 (or very small numbers, on the order of 10^0) my plot of the solution becomes almost chaotic. I thought the case x0=0 and v0=0 is covered by the default case in Piecewise so that the particle should not move at all under these conditions. What can I do to fix this?
[toc] | [next] | [standalone]
| From | DC <b.gatessucks@gmail.com> |
|---|---|
| Date | 2012-08-18 07:44 +0000 |
| Message-ID | <k0nh5j$auj$1@smc.vnet.net> |
| In reply to | #11386 |
Removing the `=` in the inequalities seems to work :
g = 9.81;
b = 0.;
c = 1.0;
x0 = 0.001;
v0 = 1.001;
sol = First[
x /. NDSolve[{x''[t] ==
Piecewise[{{-g - b*x'[t], x[t] > 0 && x'[t] > 0}, {-g - c*x'[t],
x[t] > 0 && x'[t] < 0}, {g - b*x'[t],
x[t] < 0 && x'[t] < 0}, {g - c*x'[t],
x[t] < 0 && x'[t] > 0}}, 0.], x'[0] == v0, x[0] == x0},
x, {t, 0, 1}, MaxSteps -> \[Infinity], AccuracyGoal -> 3]]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web