{"id":222213,"date":"2025-05-31T06:46:29","date_gmt":"2025-05-31T06:46:29","guid":{"rendered":"https:\/\/learnexams.com\/blog\/?p=222213"},"modified":"2025-05-31T06:46:31","modified_gmt":"2025-05-31T06:46:31","slug":"write-a-code-in-matlab-to-show-routh-stability-criterion-with-gui-and-show-it-on-a-graph-please","status":"publish","type":"post","link":"https:\/\/www.learnexams.com\/blog\/2025\/05\/31\/write-a-code-in-matlab-to-show-routh-stability-criterion-with-gui-and-show-it-on-a-graph-please\/","title":{"rendered":"Write a code in Matlab to show Routh stability criterion with GUI and show it on a graph please."},"content":{"rendered":"\n<p>Write a code in Matlab to show Routh stability criterion with GUI and show it on a graph please. thank you. (please explain it clearly)<\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">The Correct Answer and Explanation is:<\/mark><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 <strong>MATLAB Code (Routh Stability with GUI and Graph)<\/strong><\/h3>\n\n\n\n<p>Save this file as <code>routh_gui.m<\/code> and run it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function routh_gui\n    % Create a simple GUI for Routh-Hurwitz criterion\n\n    % Main figure\n    f = figure('Name','Routh Stability Criterion','Position',&#91;500 300 500 400]);\n\n    % Input label and field\n    uicontrol('Style','text','Position',&#91;50 340 400 30],'String','Enter the coefficients of the characteristic polynomial (highest power first):');\n    coeffBox = uicontrol('Style','edit','Position',&#91;50 310 400 30],'String','1 3 2 4');\n\n    % Button to compute stability\n    uicontrol('Style','pushbutton','Position',&#91;200 270 100 30],'String','Check Stability',...\n              'Callback',@checkStability);\n\n    % Axes for plot\n    ax = axes('Units','pixels','Position',&#91;75 50 350 200]);\n\n    function checkStability(~,~)\n        % Get user input and convert to numeric\n        coeffStr = get(coeffBox, 'String');\n        coeffs = str2num(coeffStr); %#ok&lt;ST2NM&gt;\n\n        if isempty(coeffs) || ~isnumeric(coeffs)\n            msgbox('Please enter valid numeric coefficients.','Error','error');\n            return;\n        end\n\n        % Routh-Hurwitz calculation\n        &#91;stable, rhTable] = routh_criterion(coeffs);\n        \n        % Display results\n        if stable\n            msg = 'System is STABLE: All first column elements have same sign.';\n        else\n            msg = 'System is UNSTABLE: Sign change(s) detected in first column.';\n        end\n        msgbox(msg, 'Stability Result');\n\n        % Plot poles\n        roots_poly = roots(coeffs);\n        cla(ax);\n        plot(ax, real(roots_poly), imag(roots_poly), 'rx', 'MarkerSize',10, 'LineWidth',2);\n        hold(ax, 'on');\n        plot(ax, &#91;0 0], ylim(ax), 'k--');  % y-axis\n        title(ax, 'Pole Locations (Root Locus)');\n        xlabel(ax, 'Real Axis');\n        ylabel(ax, 'Imaginary Axis');\n        grid(ax, 'on');\n        hold(ax, 'off');\n    end\nend\n\n% ---------- Helper Function: Routh Table ----------\nfunction &#91;isStable, routhTable] = routh_criterion(coeffs)\n    n = length(coeffs);\n    routhTable = zeros(n, ceil(n\/2));\n    \n    % First two rows\n    routhTable(1, :) = coeffs(1:2:end);\n    routhTable(2, 1:min(length(coeffs)-1, ceil(n\/2))) = coeffs(2:2:end);\n\n    for i = 3:n\n        for j = 1:size(routhTable,2)-1\n            a = routhTable(i-2,1);\n            b = routhTable(i-2,j+1);\n            c = routhTable(i-1,1);\n            d = routhTable(i-1,j+1);\n            if c == 0, c = 1e-6; end\n            routhTable(i,j) = ((c*b)-(a*d))\/c;\n        end\n    end\n\n    first_column = routhTable(:,1);\n    first_column = first_column(~isnan(first_column) &amp; ~isinf(first_column)); % Clean\n    isStable = all(sign(first_column) &gt; 0) || all(sign(first_column) &lt; 0);\nend\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udcd8 <strong>Explanation<\/strong><\/h3>\n\n\n\n<p>The <strong>Routh-Hurwitz Stability Criterion<\/strong> is a mathematical test used in control systems to determine whether a linear time-invariant (LTI) system is stable, without explicitly calculating the roots of its characteristic equation. The test is based on constructing a <strong>Routh array (table)<\/strong> from the coefficients of the characteristic polynomial. The system is <strong>stable if and only if all the elements in the first column of the Routh table have the same sign (no sign changes).<\/strong><\/p>\n\n\n\n<p>This MATLAB GUI allows users to input the coefficients of a polynomial such as <code>1 3 2 4<\/code> (which represents s3+3s2+2s+4s^3 + 3s^2 + 2s + 4). Once entered, pressing the <strong>&#8220;Check Stability&#8221;<\/strong> button:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Parses the polynomial<\/strong>.<\/li>\n\n\n\n<li>Constructs the <strong>Routh table<\/strong> using a loop, handling zeros carefully.<\/li>\n\n\n\n<li><strong>Checks for sign changes<\/strong> in the first column.<\/li>\n\n\n\n<li>Displays a message indicating stability or instability.<\/li>\n\n\n\n<li>Plots the <strong>roots<\/strong> (system poles) on the complex plane, aiding visual understanding.<\/li>\n<\/ol>\n\n\n\n<p>Graphically, the real parts of the poles determine stability. If <strong>any pole lies in the right half-plane (RHP)<\/strong>, the system is unstable. This visualization complements the Routh test, which may be less intuitive for students or engineers unfamiliar with the method.<\/p>\n\n\n\n<p>This tool bridges theory and practice, providing both <strong>numeric analysis<\/strong> (Routh table) and <strong>visual feedback<\/strong> (root plot) \u2014 an effective educational and engineering tool for system stability analysis.<\/p>\n\n\n\n<p>Here&#8217;s a <strong>MATLAB GUI application<\/strong> that demonstrates the <strong>Routh-Hurwitz Stability Criterion<\/strong>, allowing a user to input a polynomial (characteristic equation) and see whether the system is stable. It also includes a <strong>graphical visualization<\/strong> of pole locations.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Graphically, the real parts of the poles determine stability. If <strong>any pole lies in the right half-plane (RHP)<\/strong>, the system is unstable. This visualization complements the Routh test, which may be less intuitive for students or engineers unfamiliar with the method.<\/p>\n\n\n\n<p>This tool bridges theory and practice, providing both <strong>numeric analysis<\/strong> (Routh table) and <strong>visual feedback<\/strong> (root plot) \u2014 an effective educational and engineering tool for system stability analysis.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/learnexams.com\/blog\/wp-content\/uploads\/2025\/05\/learnexams-banner8-92.jpeg\" alt=\"\" class=\"wp-image-222216\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Write a code in Matlab to show Routh stability criterion with GUI and show it on a graph please. thank you. (please explain it clearly) The Correct Answer and Explanation is: \u2705 MATLAB Code (Routh Stability with GUI and Graph) Save this file as routh_gui.m and run it: \ud83d\udcd8 Explanation The Routh-Hurwitz Stability Criterion is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-222213","post","type-post","status-publish","format-standard","hentry","category-exams-certification"],"_links":{"self":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/222213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/comments?post=222213"}],"version-history":[{"count":0,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/posts\/222213\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/media?parent=222213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/categories?post=222213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.learnexams.com\/blog\/wp-json\/wp\/v2\/tags?post=222213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}