Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Matlab] Ideal Diode (Vector Graph)?

  1. Feb 29, 2012 #1
    Hello, I am a novice in an introductory engineering problem solving course using matlab, and i'm having a bit of a problem.
    I have attached a screenshot. I know this is supposed to be pretty basic stuff, But I am hung up on it.

    Now, what I have so far:


    for k=1:1:length(t);

    if vs(k) > 0;

    else vs(k)<= 0;


    title('Problem 2(Part A)')

    Obviously I am doing something very wrong, as when it plots, I get nothing, the graph appears blank, or is a straight horizontal line at (0,0) or something. I am having trouble narrowing it down, I think the problem lies within the % for k=1:1:length(t), and the %else, or maybe I am simply doing everything wrong to begin with.

    If anyone could shed a little light, or give a nudge in the correct direction, I would be greatly appreciative. I have also attached for what the graph is supposed to look like.

    Attached Files:

    Last edited: Feb 29, 2012
  2. jcsd
  3. Mar 1, 2012 #2


    User Avatar
    Science Advisor
    Gold Member

    I think you keep getting Vs and VL confused

    if vs(k) > 0;

    shouldn't it be vL(k)=vs(k)?

    Also, vL=0 will set the whole vector to zero; I think you mean vL(k)=0;
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook