how to plot transfer functions? in matlab

To plot transfer functions in Matlab, you first need to define the transfer function model using the built-in tf() function. The tf() function takes in two input arguments, the numerator and denominator of the transfer function in descending powers of s.

For example, let's say we want to define a transfer function with a numerator of 1 and a denominator of s^2 + 2s + 1. We can do this by defining a variable G as follows:

main.m
num = 1;
den = [1 2 1];
G = tf(num, den);
42 chars
4 lines

Once we have defined the transfer function model, we can plot it using the bode() or nyquist() functions, depending on the type of plot we want.

For a Bode plot, we can use the bode() function as follows:

main.m
bode(G);
9 chars
2 lines

This will generate a plot of the magnitude and phase of the transfer function as a function of frequency.

For a Nyquist plot, we can use the nyquist() function as follows:

main.m
nyquist(G);
12 chars
2 lines

This will generate a plot of the magnitude and phase of the transfer function as a function of frequency, but in a different format than the Bode plot.

Both the bode() and nyquist() functions have many options for customizing the plot, such as plotting multiple transfer functions on the same plot or changing the plot style. Refer to the Matlab documentation for more details.

gistlibby LogSnag