[Matlab] Ideal Diode (Vector Graph)?

1 reply · 5K views · last reply
qwrax
Messages
1
Reaction score
0
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:


t=(0:0.01:10);
vs=3*exp(-t/3).*(sin(pi*t));

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

if vs(k) > 0;
vs(k)=vL;

else vs(k)<= 0;
vL=0;

end
end



disp(vL)
plot(t,vL)
xlabel('Seconds')
ylabel('Voltage')
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.
 
Attachments
  • Textbook problem statement: ideal diode half-wave rectifier, with vL equal to vs when vs > 0 and 0 when vs ≤ 0, and supply vs(t) = 3e^(-t/3) sin(πt) volts for 0 ≤ t ≤ 10 seconds.
    Capture.PNG
    22.3 KB · Views: 1,011
  • Plot of a rectified decaying sinusoid with five separate blue arches on axes from 0 to 10; peak heights decrease from about 2.5 to about 0.2, with zero values between arches.
    graph.PNG
    1.4 KB · Views: 807
Last edited:
I think you keep getting Vs and VL confused

if vs(k) > 0;
vs(k)=vL;

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;