Connect with us

Simple RLC circuit calculation not working correctly -- why?

Discussion in 'Electronic Design' started by Steven O., Mar 4, 2006.

Scroll to continue with content
  1. Steven O.

    Steven O. Guest

    Hi, kind of a Matlab newbie here, so maybe this will be a no-brainer
    for Matlab pros, but I can use some help. Am trying to simulate a
    simple RLC circuit to obtain the steady state response. I can get a
    correct answer with Mathcad, but not with Matlab. Here's the process:

    EDU>> circuit1 = '2*pi*2000/( (2*pi*2000)^2 + s^2) = (470 + .033*s +
    (10^7)/s) * I';
    % 'I' is the current, so I am using V = I * Z

    The term on the left is the Laplace transform of a sinusoidal source,
    and the terms on the right are for the RLC circuit. (Multiplying, on
    the left, by a 1/s term for a step function does not change the
    outcome shown below.)

    EDU>> Ifr = solve(circuit1,'I')
    % Ifr stands for I_frequency_domain
    Ifr = .126e8*s/(.742e14*s+.470e6*s^3+.152e11*s^2+33.*s^4+.158e19)

    EDU>> Itd = ilaplace(Ifr); % Itd stands for I_time_domain

    EDU>> simple(Itd)
    ans =
    -.104e-2*exp(-.713e4*t)*cos(.159e5*t)
    -.149e-2*exp(-.713e4*t)*sin(.159e5*t)
    +.104e-2*exp(11.5*t)*cos(.126e5*t)
    +.129e-2*exp(11.5*t)*sin(.126e5*t)

    If we ignore the two exponentially decaying terms, the remaining two
    terms grow exponentially, which is simply not the correct steady-state
    solution. The frequencies give for the second two terms are correct
    (they equal 2 * 2000 pi, which is the source frequency, but the
    exponentially growing terms are a problem.

    One possibility I can imagine: The Matlab documentation makes clear
    that "pi" is treated as a number, not a symbolic value, so that for
    example 'sin(pi)' does not come out to exactly zero. Perhaps this
    throws off the calculations somehow!? Any help or suggestions would
    be appreciated.

    Steve O.


    "Spying On The College Of Your Choice" -- How to pick the college that is the Best Match for a high school student's needs.
    www.SpyingOnTheCollegeOfYourChoice.com
     
  2. Tim Wescott

    Tim Wescott Guest

    This probably has more to do with the fact that you are asking Matlab to
    factor a 4th-order polynomial. The polynomial _should_ have roots at
    s = +/- j12.5e3, but isn't factoring correctly because of numerical
    problems.

    Polynomial factoring is notoriously sensitive to errors in the
    coefficients, and you're doing this math in floating point. I think
    you're just asking too much of the algorithm (MathCad, obviously, is
    either using more precision or playing fancy tricks to make things come
    out right, which is cool for them, but doesn't help you if you must use
    MatLab).

    I honestly don't know what precision MatLab uses when it does these
    calculations; it might be worth some digging to find out what precision
    they use and what algorithm -- then you could calculate the expected
    precision of the result and see if things match up.

    I use SciLab, which easily lets you express systems in a state space
    form. If I had to get this answer numerically from that tool I would
    keep the RLC system in state space, and build a system who's impulse
    response was a cosine wave. Then I'd cascade them (keeping them state
    space) and see what sort of response came out. This has the advantage
    that the state-space system representation can have much better
    numerical conditioning* than the polynomial form.

    You could also get the impulse response for the filter in terms of the
    sum of two complex single-order systems, and break the cosine wave down
    with the Euler identity into the sum of two complex single-order
    signals. Then you could take these four elements, multiply them out
    (remember FOIL**?), solve for all the bits & pieces, and put it back
    together again.

    * OTOH, it can be just as bad, or worse -- you have to know what'll be
    good going in.

    ** First Outer Inner Last, although LOIF, FLOI, FOLI and other
    combinations work as well.

    --

    Tim Wescott
    Wescott Design Services
    http://www.wescottdesign.com

    Posting from Google? See http://cfaj.freeshell.org/google/
     
  3. Reg Edwards

    Reg Edwards Guest

    To understand simple L and C tuned circuits you can do no better than
    download program QL_QC and program LCR from website below.

    Download programs in a few seconds and run immediately under
    DOS-Windows. Not zipped up.
    ----
    ............................................................
    Regards from Reg, G4FGQ
    For Free Radio Design Software go to
    http://www.btinternet.com/~g4fgq.regp
    ............................................................
     
  4. Steven O.

    Steven O. Guest

    I'm sure it's a great program, but Matlab is required for the class.

    Steve O.


    "Spying On The College Of Your Choice" -- How to pick the college that is the Best Match for a high school student's needs.
    www.SpyingOnTheCollegeOfYourChoice.com
     
  5. The Phantom

    The Phantom Guest

    The problem is that you only have 3 digits in your coefficients in this
    expression. Leave everything in factored form:

    4E6*pi*s
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-