Roots of Algebraic and Transcendental Equations
4.5 MATLAB’s fzero and roots Functions
4.5.2 The roots Function
MATLAB has a function to obtain the roots of a polynomial. The function is roots. To obtain the usage of the function, in the Command Window type
>> help roots This gives
ROOTS Find polynomial roots.
ROOTS(C) computes the roots of the polynomial whose
coefficients are the elements of the vector C. If C has N+1 components, the polynomial is C(1)*X^N +... + C(N)*X + C(N+1).
Thus, to find the roots of the polynomial Ax4+Bx3+Cx2+Dx E+ =0, run roots([A B C D E]). The roots function will give both real and imaginary roots of the polynomial.
Some additional useful MATLAB functions are
poly(V) Finds the coefficients of the polynomial whose roots are V real(X) Gives the real part of X
imag(X) Gives the imaginary part of X
Example 4.2: Using roots to Find the Zeros of a Polynomial
% Example_4_2.m
% This program determines the roots of a polynomial using
% the built in function 'roots'.
% The first polynomial is: f=x^3-4.7*x^2-35.1*x+85.176.
% The roots of this polynomial are all real.
% The second polynomial is: f=x^3-9*x^2+23*x-65. The
% roots of this polynomial are both real and complex.
% Complex roots must be complex conjugates.
% To obtain more info on complex numbers in MATLAB, run
% "help complex" in the Command Window.
clear; clc;
% Define coefficients of first polynomial (real roots) C(1)=1.0; C(2)=-4.7; C(3)=-35.1; C(4)=85.176;
fprintf('The first polynomial coefficients are:\n');
C
fprintf('The roots are: \n');
V=roots(C)
fprintf('The recalculated coefficients of the ');
fprintf('polynomial whose roots are V are:\n');
C_recalc=poly(V) fprintf('\n\n');
% Define coefficients of second polynomial (real and
% complex roots)
D(1)=1.0; D(2)=-9.0; D(3)=23.0; D(4)=-65.0;
fprintf('The second polynomial coefficients are:\n');
D
fprintf('The roots are: \n');
W=roots(D)
fprintf('The real and imaginary parts of the ');
fprintf('roots are:\n');
re=real(W) im=imag(W)
fprintf('The recalculated coefficients of the ');
fprintf('polynomial whose roots are W are:\n');
W_recalc=poly(W)
Projects
Project.4.1
The current-voltage relationship of a semiconductor PN diode can be written as follows:
= −1
iD I eS q kTvD
(P4.1a)
where iD and vD are the diode current and voltage, respectively, as defined in Figure P4.1; IS is a constant (with units of amperes), which is determined by the semicon-ductor doping concentrations and the device geometry; q=1.6 10× −19 coulomb is the unit electric charge; k=1.38 10× −23 joule/kelvin is the Boltzmann constant;
and T is absolute temperature (in kelvin).
We would like to determine the current and voltage through the diode for this circuit. Using Kirchhoff’s voltage law, we know that the sum of the voltage drops around the circuit must sum to zero:
Vin−vR−vD=0 (P4.1b)
Applying Ohm’s law for the current through the resistor vR=i RR and observ-ing that the resistor current equals the diode current iR=iD, we can rewrite Equation (P4.1b) as
1. Create a MATLAB function for f(vD) and plot for the interval 0ʺvDʺ 0.8V for 10 mV steps (80 subdivisions on the vD domain).
2. Use the search method to obtain a small interval within which the root of Equation (P4.1c) lies.
3. Use MATLAB’s fzero function to obtain a more accurate value for the root.
Use the following parameters:
T = 300K, IS = 10–14A, Vin = 5V, R = 1000 Ω.
Project.4.2
We wish to determine the DC transfer characteristic for the diode circuit of Figure P4.1. We will consider Vin as a parameter, where 5VʺVinʺ12V in steps of 1 V.
We wish to find the value of vD for all values of Vin.
−
Figure P4.1 Diode-resistor circuit.
Write a MATLAB program that will find the roots of f v( )d = 0, where
1. Use a global statements to bring values of Vin into the function f(vD).
2. Take 0.2ʺvDʺ 0.8 V with 60 subdivisions on the vD domain.
3. Use the search method to find a small interval in which the root of f(vD) = 0 lies.
4. Use the MATLAB’s fzero function to obtain a more accurate value for the root.
5. Construct a table consisting of all values of Vin and the corresponding roots of f(vD) = 0.
6. If you did Project 4.1, confirm that your program returns the same result as in Project 4.1 when Vin=5 V.
Project.4.3
Repeat Project 4.2, but this time do not use global statements. Instead, modify your f v( )d function to include the argument Vin. You will also need to modify the fzero statement appropriately to use a function with multiple arguments.
Project.4.4
We wish to consider the settling time (described in the following) of the inductor current iL in the RLC circuit of Section 2.17 and Project 2.9. The resistance Rcrit that makes the circuit critically damped is given by
= 4
R L
crit C
For R R> crit, the governing equation describing iL is
The settling time of a waveform is the time tsettle that it takes the waveform (iL) to reach within a percentage of some specified value and stay within that range (see Figure P4.4). For this problem, we will take the settling time for iL(t) to be within ±10% of the initial value iL (0) and stay within that range. Write a MATLAB program that deter-mines the settling time for the following circuit parameters:
R=4Rcrit, L=1.0 mH, C=1.0 F, iL(0) 0.25 A, (0) 6 V, 0= v = ≤ ≤t 1000 s 1. Create a plot of iL(t) versus t. On the same plot, create the lines 0.1 (0)iL and
−0.1 (0)iL .
2. Use the search method and MATLAB’s fzero function to determine the settling time of iL(t). Hint: Use | ( )|i tL and the 0.1 (0)iL line to find the maxi-mum root, thus determining the settling time.
Project.4.5
An n-channel metal-oxide-semiconductor field-effect transistor (MOSFET) is shown in Figure P4.5a. The MOSFET has three terminals: gate, source, and drain.
(Actually, MOSFETs also have a fourth bulk terminal, which we do not discuss here.) In MOSFET circuits, we are usually concerned with the drain current iD as
0.05
–0.05 tsettle t
iL
0.5
0
Figure P4.4 The settling time tsettle is defined as the time it takes for iL to reach and stay within some error band of its final value. This problem uses an error band of ±10%, but error bands of ±5% or ±2% are also common.
iD
vGS +
− vDS
+
− Drain terminal
Source terminal terminalGate
(a)
Typical Output Characteristics
30 Drain to Source Voltage VDS (V)
40
20 50
10 Drain Current ID (A)
0 2 4 6 8 10
VGS = 10 V TC = 25°C
1 2 0 5
6 7 8 9
Pch = 100 3 W 4
(b)
Figure P4.5 (a) An n-channel MOS transistor and its defined terminal param-eters. (b) Terminal characteristics of the 2SK1056 power MOSFET. (Courtesy of Renesas Electronics Corporation.)
a function of the terminal voltages. A common mathematical model for the drain current iD for an n-channel MOSFET [1] is as follows:
( )
where iD is defined in Figure P4.5a; vGS and vDS are the transistor gate-to-source and drain-to-source voltages, respectively; Vth is the transistor “threshold voltage”;and K and λ are constants that are dependent on silicon doping levels, electron mobility, and device geometry. Figure P4.5b shows a plot of typical iD as a function of vDS (for various fixed values of vGS) for the 2SK1056 power MOSFET.
1. Create a MATLAB function id _ powerfet that takes two arguments vds and vgs and computes the MOSFET current id as defined by Equation (P4.5a). Take
Vth=0.2 V, K =0.2, λ =0.01
2. Plot iD as a function of vDS for 0ʺvDSʺ 50 V for values of
=1,2, 3, 4, 5, 6, 7, and 8
vGS V. Your plot should look similar (but not identi-cal) to the one in Figure P4.5b.
3. Because the 2SK1056 is rated for a maximum of 100 W, Figure P4.5b does not show values of iD under conditions where the total device power P i= D×vDS exceeds 100 W. Modify your function definition for id _ powerfet to check the device power and return NaN (not a number) if the power exceeds 100 W. Rerun your plot and confirm that it now resembles Figure P4.5b.
4. Use the fzero function to find the value of vGS when vDS = 5 V and iD = 2 A.
Hint: For this problem, you will need to solve id _ powerfet as a function of vGS with vDS andiD as fixed parameters.
Project.4.6
The simplest digital logic gate is the inverter (Figure P4.6a), which converts a Boolean “true” into “false” and vice versa. In electronics, we often represent a logi-cal true as a high voltage (e.g., +5 V) and false as a low voltage (e.g., 0 V). Thus, from an electronic standpoint, an inverter is a circuit that accepts a +5 V input and outputs 0 V and accepts a 0 V input and outputs +5 V. A simple circuit that implements these requirements is the resistor-MOSFET circuit of Figure P4.6b and is a form of resistor-transistor logic (RTL). In this case, an n-channel MOSFET is loaded with a 2-kΩ resistor, VDD is the power supply voltage (typically 5 V), vin is the input (and is equal to vGS), and vout is the output (and is equal to vDS).
Using Kirchhoff’s voltage law, we can write an equation for the output voltage loop:
VDD−vR−vDS=0 (P4.6a)
By Ohm’s law,
vR=i RD (P4.6b)
Substituting Equation (P4.6b) into Equation (P4.6a) gives
VDD−i R vD − DS=0 (P4.6c)
where iD is determined by Equation (P4.5a).
Create a MATLAB program that uses MATLAB’s fzero function to deter-mine the roots of Equation (P4.6c). Use the following n-channel MOSFET parameters: VDD = 5 V, Vth = 0.7 V, K = 0.0005, and λ = 0.05. Take 0 ≤ vDS ≤ 5 V in steps of 0.1 V and 0 ≤ vGS ≤ 5 V in steps of 0.1 V. In actuality, a range of voltages is considered a valid “low” or a valid “high” signal. For the RTL inverter described here, assume that the range 0−1 V constitutes a valid low and 4−5 V constitutes a valid high.
1. Create a table of vout versus vin (corresponding to vDS vs. vGS).
2. Plot vout versus vin
3. Does the circuit described here behave like an inverter; that is, does a high input produce a low output and vice versa?
4. The inverter noise margin is defined as the amount of noise allowed on a valid input such that the output remains valid. For example, if vin raised above the legal range for a low, say to 1.1 V, does the output remain a valid high? Find the highest low vin that still produces a valid high vout. Also, find the lowest high vin that still produces a valid low vout. Print these values to the screen.
vin vout
(a)
R
iD vGS
+
− vDS
+
− vR +
−
vin
vout VDD
(b)
Figure P4.6 (a) Logic inverter. (b) RTL inverter circuit using an n-channel MOS transistor.
Project.4.7
The RTL logic family of Project 4.6 was typically used in the 1950s when transis-tors were expensive (and packaged individually) and resistors were cheap. When integrated circuits were invented in the 1960s, the opposite became true: transis-tors became very cheap, and resistors became comparatively expensive (because they are inefficient to implement on a chip).
Figure P4.7a shows a complementary MOSFET (CMOS) inverter. In this case, the resistor is replaced by a p-channel MOSFET. We can mathematically model
vGS,n +
− vDS,n
+
−
vin vout
VDD
vGS,p
−
+ vDS,p−
iD,p +
iD,n
(a)
vDS,p
−
+ vGS,p
−
+
iD,p
Source terminal
terminalGate
Drain terminal (b)
Figure P4.7 (a) CMOS inverter circuit. (b) A p-channel MOS transistor and its defined terminal parameters.
the p-channel MOSFET similarly to the n-channel MOSFET of Project 4.5; that is, the p-channel drain current iD,P is given by
where vGS p, , vDS p, , and iD p, are as defined in Figure P4.7b. Note that the p-channel model mentioned is similar to the n-channel model of Equation (P 4.5a) except for some sign changes. In addition, for a given integrated circuit technology, the values of Vth, K, and λ will be different for p- versus n-channel MOSFETs (and thus will be denoted with p and n subscripts, respectively). Kirchhoff’s voltage law
where the n-channel source current iD n, is defined as
( )
1. Create a MATLAB program using the fzero function to obtain the roots of Equation (P4.7f) by applying equations (P4.7a) and (P4.7g). Take VDD = 5V, Vth,n
= 0.7 V, Vth,p = –0.8 V, Kn = 0.0005, Kp = 0.00015, λn = 0.05, and λp = 0.1. Assume
ʺ ʺ
0 vout 5 V in steps of 0.1 V and 0ʺ vinʺ 5 V in steps of 0.1 V.
2. Create a table of vout versus vin. 3. Plot vout versus vin.
4. Does the circuit described here behave like an inverter? That is, does a high input produce a low output and vice versa?
Reference
1. A.S. Sedra and K.C. Smith, Microelectronic Circuits, 3rd ed., Saunders College, Philadelphia, 1989.
129