How to solve the following equations for Vc(t)?

4 views (last 30 days)
How can I solve the following problem? The capacitor voltage.
Vc(t) = 1/c * Int (Ic(t))dt + Vc(0)
function [Ic,Vc] = fcn(S1,S2,S3,S4,Is1)
Ic = (S1*S4+S2*S3)*Is1; %capacitor current - it´s working
Vc= 1/0.01*int(Ic,t) + 2000;
I have the capacitor current flowing, it will depend on which switch is on. So I will have my chain as a function of time. But to know the value of the capacitor voltage in each time it is necessary to integrate the capacitor current as a function of time

Answers (1)

Alan Stevens
Alan Stevens on 7 Sep 2020
Edited: Alan Stevens on 7 Sep 2020
Can you do it using the differential form of the relationship between Vc and Ic? Something like the following (obviously, you would need to replace my arbitrary data/functions with your own):
% dVc/dt = (1/c)Ic with Vc(0)
Is1 = @(t) exp(-t);
tspan = [0 3];
Vc0 = 2000;
[t, Vc] = ode45(@rate,tspan, Vc0,[],Is1);
plot(t,Vc)
xlabel('time'),ylabel('Vc')
function dVcdt = rate(t,~,Is1)
c = 0.01;
dVcdt = Sfn(t).*Is1(t)/c;
end
function S = Sfn(t)
if t<0.5
S1 = 1; S2 = 0; S3 = 0; S4 = 1;
elseif t < 1
S1 = 0; S2 = 0; S3 = 0; S4 = 0;
else
S1 = 0; S2 = 1; S3 = 1; S4 = 0;
end
S = S1*S4 + S2*S3;
end
  6 Comments
Yelena
Yelena on 8 Sep 2020
No, but k is my time so it´ll be integer values. Or not?
Alan Stevens
Alan Stevens on 8 Sep 2020
A little more like this, perhaps:
Is1 = @(t) exp(-t);
Icfn = @(t) Sfn(t).*Is1(t);
N = 100; % Nbr of timesteps
T = 3; % End time
C = 0.01;
V0 = 2000;
Vc = zeros(1,N); Vc(1) = V0;
Ic = zeros(1,N); Ic(1) = Is1(0);
dt = T/N;
t = 0:dt:T-dt;
for i = 2:numel(t)
Ic(i) = Icfn(t(i));
Vc(i) = integral(Icfn,t(i-1),t(i))*dt/C +Vc(i-1);
end
subplot(3,1,1)
plot(t,Ic),ylabel('Ic')
xlabel('time'),ylabel('Ic')
subplot(3,1,2)
plot(t,Vc)
xlabel('time'),ylabel('Vc')
subplot(3,1,3)
plot(Ic,Vc)
xlabel('Ic'),ylabel('Vc')
function S = Sfn(t)
if t<0.5
S1 = 1; S2 = 0; S3 = 0; S4 = 1;
elseif t < 1
S1 = 0; S2 = 0; S3 = 0; S4 = 0;
else
S1 = 0; S2 = 1; S3 = 1; S4 = 0;
end
S = S1*S4 + S2*S3;
end

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!