MATLAB Answers

How do I plot a transient voltage response before and after a switch is thrown?

1 view (last 30 days)
Rafael Estrada
Rafael Estrada on 26 Nov 2020
Commented: Rafael Estrada on 26 Nov 2020
I currently have the following code:
% Define the time step
% x = [ start: step: stop]
t = [ - 10e-6 : 1e-8 : 150e-6];
% BEFORE SWITCH IS THROWN
Vc(t<0) = 4.604;
% AFTER SWITCH IS THROWN
Req = 6.334e3;
C = 2.7e-9;
tau = Req * C;
Vc(t>0) = 4.604 * (1 + exp(-t / tau));
plot(t, Vc);
title('Capacitor Voltage vs Time');
xlabel('Time (s)');
ylabel('Voltage (V)');
I need to plot the DC voltage before time is 0 as a flat line at 4.604V, then after as an exponential decay.
Have been trying for a while and can't seem to get it. Any tips would be very appreciated!

  0 Comments

Sign in to comment.

Accepted Answer

VBBV
VBBV on 26 Nov 2020
Edited: VBBV on 26 Nov 2020
%if true
Vc(t>0) = 4.604 * (1 + exp(-t(t>0)./ tau));
plot(t, Vc);
title('Capacitor Voltage vs Time');
xlabel('Time (s)');
ylabel('Voltage (V)');

More Answers (0)

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!