[Matlab] Ideal Diode (Vector Graph)?

  • Context: MATLAB 
  • Thread starter Thread starter qwrax
  • Start date Start date
  • Tags Tags
    Diode Graph Matlab
Click For Summary
SUMMARY

The forum discussion centers on troubleshooting a MATLAB script designed to model an ideal diode's behavior in an engineering context. The user is attempting to plot the voltage across the load (vL) based on the input voltage (vs), but encounters issues resulting in a blank graph. Key errors identified include the incorrect assignment of values to vL and the need to update vL at each index rather than setting it to zero for the entire vector. The correct approach involves using vL(k) instead of vL=0 to ensure proper indexing and plotting.

PREREQUISITES
  • Basic understanding of MATLAB programming
  • Familiarity with vector operations in MATLAB
  • Knowledge of electrical engineering concepts related to ideal diodes
  • Experience with plotting functions in MATLAB
NEXT STEPS
  • Review MATLAB vector indexing and assignment techniques
  • Learn about MATLAB plotting functions and their parameters
  • Study the behavior of ideal diodes in electrical circuits
  • Explore MATLAB's debugging tools to troubleshoot scripts effectively
USEFUL FOR

This discussion is beneficial for novice engineers, students in introductory engineering courses, and anyone learning to use MATLAB for modeling electrical components.

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

  • Capture.PNG
    Capture.PNG
    22.3 KB · Views: 989
  • graph.PNG
    graph.PNG
    1.4 KB · Views: 783
Last edited:
Physics news on Phys.org
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;
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K