Voltage of a capacitor as a function of time
19 views (last 30 days)
Show older comments
Trey Blackwell
on 18 Mar 2020
Commented: Trey Blackwell
on 18 Mar 2020
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
Accepted Answer
James Tursa
on 18 Mar 2020
Maybe the function you want is cumsum( ) instead of sum( )?
7 Comments
James Tursa
on 18 Mar 2020
Edited: James Tursa
on 18 Mar 2020
Yes, as long as the values in t correspond to the values in I.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!