Plotting energy and power in MATLAB

Status
Not open for further replies.

Sean87

Newbie level 6
Joined
Jan 6, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Netherlands
Activity points
1,366
Hi all,

Maybe this is a noob question but I just started working with MATLAB and really no big idea on how to use its commands and functions.

I have a AC circuit with following equations:
**broken link removed**


plotting the voltage, current and power wasn't that hard (I think I wrote the correct code, please tell me if you think it's wrong!):

Code:
%Variables 
t1=20e-3;t2=60e-3;N=1000;f=50; 
t=linspace(t1,t2,N); 
Vmax = 10; %Peak Voltage 
Imax = 2; %Peak Current 
f = 50; %Frequency in Hertz 
omega = 2 * pi * f; 
phi_default = -pi/4; %Constant for phase difference 
 
%Equations 
Vsrc = Vmax * sin(omega * t); %Equation for Voltage 
Isrc = Imax * sin((omega * t) + phi_default); %Equation for Current 
Psrc = Vsrc .* Isrc; %Equation for Power 
 
%Plotting the result 
figure(1); %Window 1 
plot(t,Vsrc, 'b', t, Isrc, 'r', t, Psrc, 'g'); %Plotting Voltage, Current and Power

Now the problem is that I can't figure out a way to plot Energy in matlab. I think Δt (Delta t) should be defined maybe using diff(t) function and total energy should be something like:



And average power Pavr is calculated by \[\frac{ Wtot}{T}\] Where T is period.

So the question is, how can I plot the total instantaneous energy as a function of phase difference in range for this I think a for loop should be necessery to calculate for each phase value.

Also I want to plot the average power in the same period.

Thanks in advance for tips and tricks!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…