⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frdemo.m

📁 similer program for matlab
💻 M
📖 第 1 页 / 共 2 页
字号:
          prompt        endif      endwhile    elseif (j == 2)      k2 = 0;      disp("");      while (k2 != 4)        disp("\n");        help nyquist        prompt;        disp("")        clc;        k2 = menu("Nyquist analysis (Nyquist)",                  "Continuous system nyquist analysis",                  "Discrete system nyquist analysis",                  "Mixed system nyquist analysis",                  "Return to frdemo menu");        if( k2 == 1 )          disp("")          clc          disp("\nContinuous system nyquist analysis\n");          disp("Display Nyquist plots of a SISO system (nyquist)\n")          disp("Example #1, Consider the following transfer function:\n")          cmd = "sys1 = tf(1, [1, 0.8, 1]);";          disp(cmd);          eval(cmd);          disp("To examine the transfer function, use the command:");          cmd = "sysout(sys1);";          disp(cmd);          eval(cmd);          disp("\nTo examine the open loop zeros and poles, use the command:");          cmd = "sysout(sys1,""zp"");";          run_cmd;          disp("\nTo view the system""s nyquist plot, execute the following");          disp("command:\n")          cmd = "nyquist(sys1);";          run_cmd;          disp("\nIf the real and imaginary parts of the response are desired,");          disp("use the following command:");          disp("command: [R,I,w]=nyquist(sys1);\n");          disp("If the user desires to evaluate the response in a certain");          disp("frequency range, he may do so by entering the following:");          disp("command: [M,P,w]=nyquist(num,den,wrange).\n")          disp("wrange is a vector of frequencies that spans the desired");          disp("viewing range.\n");          disp("This will be illustrated in the third nyquist example.\n")          disp("Variable Description:\n")          disp("R => real part of response")          disp("I => imaginary part of response")          disp("w => frequencies that the transfer function was evaluated at")          disp("sys1 => system data structure")          disp("wrange => optional vector of frequencies")          disp("          if wrange is entered in the argument list, the");          disp("          system will be evaluated at these specific");          disp("          frequencies\n")          prompt          disp("")          clc          disp("Example #2, Consider the following set of poles and zeros:\n")          cmd = "sys2 = zp([-1;-4],[-2+1.4142i;-2-1.4142i],1);";          disp(cmd);          eval(cmd);          disp("\nTo examine the poles and zeros, use the command:");          cmd = "sysout(sys2)";          disp(cmd);          eval(cmd);          disp("\nTo view the system""s nyquist plot, execute the following");          disp("command:\n")          cmd = "nyquist(sys2);";          run_cmd;          prompt          disp("")          clc          disp("\nExample #3, Consider the following state space system:\n")          cmd = "sys3 = ss([0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 0, -20, -12],[0;0;0;1],[50, 100, 0, 0],0);";          disp(cmd);          eval(cmd);          disp("\nTo examine the state-space system, use the command:");          cmd = "sysout(sys3)";          disp(cmd);          eval(cmd);          disp("\nTo examine the poles and zeros, use the command:");          cmd = "sysout(sys3,""zp"")";          run_cmd;          disp("\nTo view the system""s nyquist plot, execute the following");          disp("commands:\n")          cmd = "nyquist(sys3);";          run_cmd;          prompt          disp("Example #3 (continued), If the user wishes to evaluate the");          disp("system response over a desired frequency range, he must first");          disp("create a frequency vector.\n")          disp("For example, suppose the user is interested in the response");          disp("of the system defined above over input frequency range of");          disp("3 - 100 rad/s.\n")          disp("A frequency vector can be created using the command:\n");          cmd = "wrange = logspace(log10(3),log10(100),100);";          disp(cmd);          eval(cmd);          disp("\nNyquist can be run again using the frequency vector as");          disp("follows:\n")          cmd = "nyquist(sys3,wrange);";          run_cmd;          prompt          disp("")          clc          disp("Example #4,  Nyquist can be used for MIMO systems if the system has");          disp("an equal number of inputs and outputs.  Otherwise, nyquist returns");          disp("an error.  To examine a MIMO system, systems 2 and 3 will be grouped");          cmd = "[nn,nz] = sysdimensions(sys2);";          disp(cmd); eval(cmd);          cmd = "sys2 = syssetsignals(sys2,\"out\",\"y_sys2\");";          disp(cmd); eval(cmd);          cmd = "sys2 = syssetsignals(sys2,\"in\",\"u_sys2\");";          disp(cmd); eval(cmd);          cmd = "sys2 = syssetsignals(sys2,\"st\",__sysdefioname__(nn+nz,\"x_sys2\"));";          disp(cmd); eval(cmd);          cmd = "sys_mimo = sysgroup(sys2,sys3);";          disp(cmd); eval(cmd);          cmd = "sysout(sys_mimo);";          disp(cmd);          eval(cmd);          disp("\nTo view the system's nyquist plot, execute the following command:\n")          cmd = "nyquist(sys_mimo);";          run_cmd;          prompt          disp("\nTo view the nyquist plots for selected  channels, the command form changes:")          cmd = "nyquist(sys_mimo,[],1,1);";          run_cmd;          disp("\nNotice that this bode plot is the same as the plot from example 2.");          prompt          closeplot        elseif( k2 == 2 )          disp("")          clc          disp("\nDiscrete system nyquist analysis\n");          disp("Display Nyquist plots of a discrete SISO system (nyquist)\n")          disp("We will first define a sampling time, T");          cmd = "T = 0.01;";          disp(cmd);          eval(cmd);          disp("\nExample #1, Consider the following transfer function:\n")          cmd = "sys1 = tf([2, -3.4, 1.5],[1, -1.6, 0.8],T);";          disp(cmd);          eval(cmd);          disp("To examine the transfer function, use the command:");          cmd = "sysout(sys1);";          disp(cmd);          eval(cmd);          disp("\nTo examine the open loop zeros and poles, use the command:");          cmd = "sysout(sys1,""zp"")";          disp(cmd);          eval(cmd);          disp("\nTo view the system""s nyquist plot, execute the following");          disp("command:")          cmd = "nyquist(sys1);";          run_cmd;          disp("To change the range used for the frequency, a frequency");          disp("is needed.  Suppose the user would like to examine the");          disp("nyquist plot in the frequency range of 0.01 - 31.6 rad/s.");          disp("\nThe frequency vector needed to do this is created with the");          disp("command:");          cmd = "wrange = logspace(-2,1.5,200);";          disp(cmd);          eval(cmd);          disp("\nNyquist can be run again with this frequency vector");          cmd = "nyquist(sys1,wrange);";          run_cmd;          disp("\nIf the real and imaginary parts of the response are desired,");          disp("perform the following command:\n");          disp("[R,I,w]=nyquist(sys,wrange)\n")          disp("Variable Description:\n")          disp("R => real part of response")          disp("I => imaginary part of response")          disp("w => frequencies that the transfer function was evaluated at")          disp("sys => The system data structure");          disp("wrange => optional vector of frequencies")          disp("          if wrange is entered in the argument list, the");          disp("          system will be evaluated at these specific");          prompt          disp("")          clc          disp("\nExample #2, Consider the following set of poles and zeros:\n")          cmd = "sys2 = zp([0.98025 + 0.01397i; 0.98025 - 0.01397i],[0.96079;0.99005],1,T);";          disp(cmd);          eval(cmd);          disp("\nTo examine the open loop zeros and poles, use the command:");          cmd = "sysout(sys2)";          disp(cmd);          eval(cmd);          disp("\nTo view the system's nyquist plot between the frequencies");          disp("0.01 - 100 rad/s, execute the following commands:\n")          cmd = "wrange = logspace(-2,2,100);";          disp(cmd);          eval(cmd);          cmd = "nyquist(sys2,wrange);";          run_cmd;          prompt;          disp("")          clc          disp("\nExample #3, Consider the following discrete state space");          disp("system:\n");          disp("This example will use the same system used in the third");          disp("example in the continuous nyquist demo.  First, that system");          disp("will have to be re-entered useing the following commands:\n");          cmd = "sys3 = ss([0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1; 0, 0, -20, -12],[0;0;0;1],[50, 100, 0, 0],0);";          disp(cmd);          eval(cmd);          disp("\nTo examine the state-space system, use the command:");          cmd = "sysout(sys3)";          disp(cmd);          eval(cmd);          disp("\nTo examine the poles and zeros, use the command:");          cmd = "sysout(sys3,""zp"")";          disp(cmd);          eval(cmd);          disp("\nTo convert the system to discrete time, we need a sampling");          disp("time which can be entered like this:");          cmd = "T = 0.01";          disp(cmd);          eval(cmd);          disp("\nNow the command, c2d, is used to convert the system from");          disp("continuous to discrete time, with the following command");          cmd = "dsys3 = c2d(sys3,T);";          run_cmd;          disp("\nTo examine the new discrete state-space system, use the");          disp("command");          cmd = "sysout(dsys3);";          disp(cmd);          eval(cmd);          disp("\nTo examine the new discrete poles and zeros, use the command:");          cmd = "sysout(dsys3,""zp"")";          disp(cmd);          eval(cmd);          disp("\nTo view the system's nyquist plot, execute the following");          disp("commands:\n");          cmd = "axis ([-4, 2, -2.5, 2.5]);";          disp(cmd); eval(cmd);          cmd = "nyquist(dsys3);";          run_cmd;          disp("Notice that the asymptotes swamp out the behavior of the plot")          disp("near the origin.  You may use interactive nyquist plots")          disp("to \"zoom in\" on a plot as follows:")          cmd = "atol = 1;";          disp(cmd)          eval(cmd)          cmd = "nyquist(dsys3,[],[],[],atol);";          run_cmd          prompt          disp("")          clc          disp("MIMO SYSTEM:  Nyquist cannot be used for discrete MIMO systems");          disp("at this time.");          ## cmd = "dsys_mimo = sysgroup(sys2,dsys3);";          ## disp(cmd);          ## eval(cmd);          ## cmd = "sysout(dsys_mimo);";          ## disp(cmd);          ## eval(cmd);          ## disp("\nTo view the system's nyquist plot, execute the following command:\n")          ## cmd = "nyquist(dsys_mimo);";          ## run_cmd;          ## prompt          ## disp("\nTo view the nyquist plots for selected  channels, the command form changes:")          ## cmd = "nyquist(dsys_mimo,[],1,1);";          ## run_cmd;          ## disp("\nNotice that this bode plot is the same as the plot from example 2.");          prompt          closeplot        elseif( k2 == 3 )          disp("\nMixed system nyquist analysis\n");          disp("Nyquist exits with an error if it is passed a ""mixed"" system (one")          disp("with both continuous and discrete states).  Use c2d or d2c to")          disp("convert the system to either pure digital or pure continuous form");        endif      endwhile    elseif (j == 3)      help nichols      prompt    endif  endwhileendfunction

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -