MATLAB Answers

Voltage of a capacitor as a function of time

4 views (last 30 days)
I'm trying to code the voltage of a capacitor as a function of time.
I is an array of current values.
t is an array of time values with a time step of 1, with corresponding to the length of I: t = 0:length(I)-1
Vi is a constant.
C is a constant
V is an array of zeros, and it is the same length as I.
The formula is V(t=T) = (1/C)*sum(I) + Vi
where sum is from 0+ to T.
I have attempted several things. Here is where I am at:
for T = t
V = Vi + (1/C).*sum(I,(0:T));
end
This gives me an error for using zero in the summation.
When I do this:
for T = t
V = Vi + (1/C).*sum(I,(1:T));
end
It compiles.
Then I try to plot it:
figure(2),clf;
plot(t, V);
xlabel ('time');
ylabel('voltage');
title('voltage vs time');
The results clearly are not correct.
I then need to calculate the Power, which I know to be:
Power = V.*I
And the energy:
Energy = (1/2)*C.*V.^2;
And plot those as well.
Thank you in advance for the assistance!

  0 Comments

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 18 Mar 2020
Maybe the function you want is cumsum( ) instead of sum( )?

  7 Comments

Show 4 older comments
Trey Blackwell
Trey Blackwell on 18 Mar 2020
T is equal to the array t, which was created:
t = 0:length(I)-1;
Is what you are saying that I can just do this?
V = Vi + (1/C).*cumsum(I)
James Tursa
James Tursa on 18 Mar 2020
Yes, as long as the values in t correspond to the values in I.
Trey Blackwell
Trey Blackwell on 18 Mar 2020
Looks like that worked! I will look a little more into that specific function to understand how it works. Thank you very much!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019b