1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Diode - RC circuit differential equation

  1. Apr 20, 2016 #1
    1. The problem statement, all variables and given/known data
    ShgElw8.png
    I'm having difficulty deriving the differential equation, this is what I have so far. In order to solve it, I will be using Matlab, and I'll be using the equation dy/dx ≈ (y(x + dx) - y(x))/dx. Is my derivation correct so far?
    2. Relevant equations
    In picture.

    3. The attempt at a solution
    OxOHvq0.jpg
    If it's correct, do I just need to make DVout/dt the subject, then apply the approx. derivative equation to then calculate the values?
     
    Last edited by a moderator: Apr 18, 2017
  2. jcsd
  3. Apr 20, 2016 #2

    gneill

    User Avatar

    Staff: Mentor

    You're on the right path, but ffter you've made your substitution for the derivative you'll want to isolate the "new" value ##v_{out}(t + dt)## so that you can calculate the new ##v_{out}## from its current value over the timestep dt.
     
  4. Apr 20, 2016 #3
    I've updated it as follows: t0RN7wl.jpg

    The problem I've had with this is that when I write a MATLAB program to solve it, and display it as a graph, it definitely doesn't seem correct. For some reason, the voltages are incredibly small, i.e. 2x10^-16.
     

    Attached Files:

    Last edited by a moderator: Apr 18, 2017
  5. Apr 20, 2016 #4

    gneill

    User Avatar

    Staff: Mentor

    Your final expression for ##v_{out}(t + dt)## looks fine. Must be something to do with how you are doing the integration in MATLAB. So you'll be looking at debugging that. Maybe running for just a few timesteps and printing out the various variable values will help.

    I'm not very familiar with MATLAB, but I get reasonable results using the same expression in MathCad.
     
  6. Apr 20, 2016 #5
    If I post the code, would you be able to see where I'm going wrong if possible? The MATLAB language is rather basic, or at least what I've wrote.
     
  7. Apr 20, 2016 #6

    gneill

    User Avatar

    Staff: Mentor

    You can post the code (be sure to use code ... \code tags around it to preserve formatting). But you really should get some experience with debugging your own code.
     
  8. Apr 20, 2016 #7
    I agree, I have tried debugging it although I honestly can't see what's wrong.

    Code (Text):

    %Variables and constants
    C = 0.001;
    R = 10;
    V0 = 2;
    f = 50;
    I = 0.000001;
    dt = 0.01;
    t = 0:dt:2;

    Vin = V0 * sin(2*pi*f*t); %Input voltage
    Vout(1) = 0; %Initial Vout

    for n = 1:length(Vin) - 1,
        Vout(n + 1) = Vout(n) - ((Vout(n) * dt) / (R * C)) + ((I * dt / C) * (exp((Vin(n) - Vout(n) ) / 0.0259) - 1));
    end

    plot(t, Vin, 'k--', t, Vout, 'k')
    ylim([0 2]); %Limits y-axis
    xlabel('time');
    ylabel('voltages');
     
     
  9. Apr 20, 2016 #8

    gneill

    User Avatar

    Staff: Mentor

    Check your timestep size. How does it compare to the period of the input waveform? What's a reasonable total time to cover, say, two full periods?
     
  10. Apr 20, 2016 #9
    I've now tidied it up, but the graph doesn't look promising. The Vin graph is fine, but the Vout isn't good at all, Vout does get quite large.
    This is the new code:
    Code (Text):

    %Variables and constants
    C = 0.001;
    R = 10;
    V0 = 2;
    f = 50;
    I = 0.000001;
    dt = 0.001;
    t = 0:dt:0.08;

    Vin = V0 * sin(2*pi*f*t); %Input voltage
    Vout(1) = 0; %Initial Vout

    for n = 1:length(Vin) - 1,
        Vout(n + 1) = Vout(n) - ((Vout(n) * dt) / (R * C)) + ((I * dt / C) * (exp((Vin(n) - Vout(n) ) / 0.0259) - 1));
    end

    plot(t, Vin, 'k--', t, Vout, 'k')
    ylim([0 2.5]); %Limits y-axis
    xlabel('time');
    ylabel('voltages')
     
    Here are the graphs:
    YNGsIkY.png
     
  11. Apr 20, 2016 #10

    gneill

    User Avatar

    Staff: Mentor

    Vin should be between + and - 2 Volts, so you'll want to adjust the y-axis for its plot.

    I think that your dt should be even smaller to begin with. Try something like a hundred "samples" per cycle of the input.

    I see that your output voltage scale looks rather large. You'll need to find out how that happened. Try printing out the terms of the equation for a few iterations and see where they're headed.
     
  12. Apr 20, 2016 #11
    Thank you very much, it is working perfectly now. I manually adjusted the scale for Vout since it was very much of the graph. Once again, thank you for your help.
     
  13. Apr 20, 2016 #12

    gneill

    User Avatar

    Staff: Mentor

    Glad I could help :smile:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Diode - RC circuit differential equation
Loading...