NDSolve problem with piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg32065] NDSolve problem with piecewise functions
- From: "Christopher R. Carlen" <crcarle at sandia.gov>
- Date: Fri, 21 Dec 2001 03:57:45 -0500 (EST)
- Organization: Sandia National Laboratories, Albuquerque, NM USA
- Sender: owner-wri-mathgroup at wolfram.com
Hi: I am using NDSolve in Mathematica 4.1.0.0 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 *) Clear[f] (* 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. Strange. Help appreciated greatly! ____________________________________ Christopher R. Carlen Principal Laser/Optical Technologist Sandia National Laboratories CA USA crcarle at sandia.gov