# How can I plot the voltage across any component by Matlab?

I want to ask how can I plot the voltage across any component by Matlab?

I have a simple RLC circuit and I want to plot the voltage across the 3 components and I didn't use Matlab before. I found the transfer function here in the site but still can't plot the voltage.

And the voltage source I will use is cosine source but I can't find it in the simulink also.

So this is what I made:

>> L = 0.047;
>> R = 220;
>> C = 0.000001;
>> Num = 1 ;
>> Denum = [L*C R*C 1 ];
>> G = tf(Num , Denum)

• Are you confusing MATLAB and SPICE? linear.com/designtools/software – Daniel Oct 6 '16 at 17:00
• Your signal in frequency domain. To draw the output with respect to time, you need to solve the differential equation of your circuit. Matlab offers ode45() regarding this matter. – CroCo Oct 10 '16 at 19:53

## 1 Answer

What you can do in MATLAB is the following:

Make a Bode plot like this:

L = 0.047; R = 220; C = 0.000001;
Num = 1 ;
Denum = [L*C R*C 1 ];
G = tf(Num , Denum);
bode(G); grid on


Or get a time-domain response like that:

omega = 4e3;
t = linspace(0, 3*2*pi/omega)
u = sin(omega * t);
lsim(G,u,t); grid on


For everything else (voltages and currents for each component) you are better off with Spice. There is also a toolbox for Simulink called SimElectronics, but I'd still prefer Spice.

• Minor mistake, the OP states "And the voltage source I will use is cosine source" but in your Matlab script, it is sin(). – CroCo Oct 10 '16 at 19:51
• @CroCro - sin is shorthand for cosine with -pi/2 phase shift. :-) – Mario Oct 10 '16 at 20:09