MATLAB: How to plot the function of Resistor Voltage Vr

MATLABresistor voltage vr

In this situation, I am assuming frequency f is a unknown varible ( just like variable x). I want to plot a graph of function Vr ( resistor voltage) in the range frequency of [0, 4e6] where Vr = (Vo*R)/Z
clear all
clc
% Define the value of R,C,L
R = 1000;
C = 120e-12;
L = 470e-6;
f = 4e6;
V0 = 220;
syms f
% Define the function of Resistor Voltage Vr
Vr = (V0*R)/sqrt((R^2)+(2*pi*f*L – 1/2*pi*f*C)^2);
fplot(@(f) Vr,[0 4e6])

Best Answer

You are almost there. Define ‘f’ as an anonymous function, vectorise it, and plot:
% Define the value of R,C,L
R = 1000;
C = 120e-12;
L = 470e-6;
f = 4e6;
V0 = 220;
% Define the function of Resistor Voltage Vr
Vr = @(f) (V0*R)./sqrt((R^2)+(2*pi*f*L - 1/2*pi*f*C).^2);
fplot(Vr,[0 4e6])
That worked when I ran it. (The Symbolic Math Toolbox ios not required here.)
From my experience, an extra set of parentheses iw likelly necessary, so consider this:
Vr = @(f) (V0*R)./sqrt((R^2)+(2*pi*f*L - 1./(2*pi*f*C)).^2);
instead.
Related Question