MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

NDSolve problem with piecewise functions

  • To: mathgroup at
  • Subject: [mg32065] NDSolve problem with piecewise functions
  • From: "Christopher R. Carlen" <crcarle at>
  • Date: Fri, 21 Dec 2001 03:57:45 -0500 (EST)
  • Organization: Sandia National Laboratories, Albuquerque, NM USA
  • Sender: owner-wri-mathgroup at


I am using NDSolve in Mathematica to do time-domain transient 
electrical circuit analysis.  I have a very simple RC high-pass filter 
circuit.  I want to calculate the output waveform when it is excited by 
various waveforms.

However, I am having problems with the output of NDSolve not making 
sense with certain excitation functions.

For example:

f[t_] := 1.0 Sin[2 Pi 60.0 t]

Plot[f[t], {t, 0, 2/60}]  (* looks like a sinewave with amplitude 1.0 *)

HighPass =
   NDSolve[ { D[Vhp[t] - f[t], t] + 1.0 Vhp[t] == 0, Vhp[0] == 0.},
     Vhp, {t, 0, 2/60}, MaxSteps -> 10000 ]

(* that's a 60 Hz sinewave into a 1Hz cutoff filter, should come through 
with almost no amplitude attenuation *)

Plot[ Vhp[t] /. HighPass[[1]], {t, 0, 2/60} ]

(* looks great, still has amplitude of about 1.0 *)


(* Now define a piecewise function that represents a sinewave with 
amplitude clipping *)

BigSine[t_] := 2.0 Sin[2 Pi 60.0 t]
f[t_] := 1.0 /;  BigSine[t] > 1.0
f[t_] := BigSine[t] /; (BigSine[t] < 1.0 && BigSine[t] > -1.0)
f[t_] := -1.0 /;  BigSine[t] < -1.0

(* go back and plot, resolve the equation, and plot the output.  There 
is no reason for the amplitude to be now 0.5 instead of 1.0 .  The shape 
makes sense, but the amplitude is 1/2 of what is expected.  What's going 
on? *)

Something seems to go wrong when using the piecewise excitation function 
in NDSolve.  I need to understand how to get this to work reliably, 
because I need to do this a lot, with eventually more complicated 
equation sets.  I have done other NDSolves with piecewise defined 
functions in the past without running into this problem.


Help appreciated greatly!

Christopher R. Carlen
Principal Laser/Optical Technologist
Sandia National Laboratories CA USA
crcarle at

  • Prev by Date: Re: Bump Function
  • Next by Date: Re: Font problems w SuSE 7.3
  • Previous by thread: Re: Solutions that are not solutions
  • Next by thread: Re: NDSolve problem with piecewise functions