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!

James Tursa
on 18 Mar 2020

Maybe the function you want is cumsum( ) instead of sum( )?

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.