{"id":42610,"date":"2025-06-29T07:10:29","date_gmt":"2025-06-29T07:10:29","guid":{"rendered":"https:\/\/gaviki.com\/blog\/?p=42610"},"modified":"2025-06-29T07:10:31","modified_gmt":"2025-06-29T07:10:31","slug":"use-matlab-using-lsim-command-or-step-command","status":"publish","type":"post","link":"https:\/\/gaviki.com\/blog\/use-matlab-using-lsim-command-or-step-command\/","title":{"rendered":"Use MATLAB using &#8220;lsim&#8221; command or &#8220;step&#8221; command"},"content":{"rendered":"\n<p>) Use MATLAB using &#8220;lsim&#8221; command or &#8220;step&#8221; command. The quarter-car model of a vehicle suspension is shown in Figure 4.5.8a. In this simplified model, the masses of the wheel, tire, and axle are neglected, and the mass m represents one-fourth of the vehicle mass. The spring constant k models the elasticity of both the tire and the suspension spring. The damping constant c models the shock absorber. The equilibrium position of m when \u00ce\u00b8 = 0 is x = 0. The road surface displacement r can be derived from the road surface profile and the car&#8217;s speed. Derive the equation of motion of m with r as the input and obtain the transfer function G(s) = Y(s)\/X(s). Assuming m = 500 kg, c = 3500 N-s\/m, and k = 6000 N\/m (all in SI units), find an expression for the transfer function. b) Assuming initial conditions to be zero, solve manually for y(t) due to an excitation x(t) = 4cos(2t) for t \u00e2\u2030\u00a5 0. c) What is the steady-state response, y_ss(t), the response as t \u00e2\u2020\u2019 \u00e2\u02c6\u017e? Express it in the form y_ss(t) = Bcos(2t) + C and compare it with the input excitation, x(t). d) (MATLAB Simulation using lsim command) Simulate the above quarter-car model in MATLAB using either lsim command or step command. Plot both the excitation, x(t), and the response, y(t), on the same figure. From your plot, determine the amplitude, frequency, and phase-shift of the steady-state output. Compare with your theoretically calculated values in part (c) above. NOTE: Determination of the phase-shift from your plot may be easier if you choose the horizontal axis to be phase t in rad, i.e., plot x(t) and y(t) against t.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"639\" height=\"700\" src=\"https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/image-491.png\" alt=\"\" class=\"wp-image-42611\" srcset=\"https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/image-491.png 639w, https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/image-491-274x300.png 274w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/figure>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">The Correct Answer and Explanation is:<\/mark><\/strong><\/p>\n\n\n\n<p>This solution addresses part (d) of the problem, which involves simulating the quarter-car model in MATLAB, analyzing the results, and comparing them to the theoretical values derived in the previous parts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Part (d): MATLAB Simulation and Analysis<\/strong><\/h3>\n\n\n\n<p>To simulate the system, we first need the transfer function,&nbsp;G(s) = Y(s)\/X(s), derived from the equation of motion:<br>m*\u00ff + c*\u1e8f + k*y = c*\u1e8b + k*x<\/p>\n\n\n\n<p>Taking the Laplace Transform gives the transfer function:<br>G(s) = (c*s + k) \/ (m*s\u00b2 + c*s + k)<\/p>\n\n\n\n<p>With the given values&nbsp;m = 500 kg,&nbsp;c = 3500 N-s\/m, and&nbsp;k = 6000 N\/m, the transfer function is:<br>G(s) = (3500s + 6000) \/ (500s\u00b2 + 3500s + 6000)<\/p>\n\n\n\n<p>This model is simulated in MATLAB using the&nbsp;lsim&nbsp;command with the input&nbsp;x(t) = 4cos(2t).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>MATLAB Code<\/strong><\/h4>\n\n\n\n<p>Generated matlab<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>% Define system parameters\nm = 500;  % kg\nc = 3500; % N-s\/m\nk = 6000; % N\/m\n\n% Define the transfer function G(s)\nnum = &#91;c, k];\nden = &#91;m, c, k];\nsys = tf(num, den);\n\n% Define time vector and input signal\nomega = 2; % rad\/s from input x(t) = 4cos(2t)\nT = 2*pi\/omega; % Period of oscillation\nt = 0:0.01:10*T; % Simulate for 10 periods\nx = 4 * cos(omega * t); % Input signal x(t)\n\n% Simulate the system's response using lsim\ny = lsim(sys, x, t);\n\n% Plot the input and output responses\nfigure;\nplot(t, x, 'b--', 'LineWidth', 1.5);\nhold on;\nplot(t, y, 'r-', 'LineWidth', 1.5);\ngrid on;\ntitle('Quarter-Car Model Response to x(t) = 4cos(2t)');\nxlabel('Time (s)');\nylabel('Displacement (m)');\nlegend('Input x(t)', 'Output y(t)');\n% Zoom into the steady-state region for clarity\nxlim(&#91;25, 32]);\nhold off;<\/code><\/pre>\n\n\n\n<p>content_copydownloadUse code&nbsp;<a href=\"https:\/\/support.google.com\/legal\/answer\/13505487\" target=\"_blank\" rel=\"noreferrer noopener\">with caution<\/a>.Matlab<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Simulation Plot<\/strong><\/h4>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Analysis and Comparison<\/strong><\/h4>\n\n\n\n<p>The plot shows the input&nbsp;x(t)&nbsp;(blue dashed line) and the system&#8217;s output response&nbsp;y(t)&nbsp;(red solid line). After an initial transient period (the first few seconds), the output settles into a sinusoidal steady-state response,&nbsp;y_ss(t).<\/p>\n\n\n\n<p>By analyzing the steady-state portion of the plot (for example,&nbsp;t &gt; 25 s), we can determine the output characteristics:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Amplitude (B):<\/strong>\u00a0The peak value of the output\u00a0y(t)\u00a0in the steady state is measured from the plot to be approximately\u00a0<strong>4.57 m<\/strong>.<\/li>\n\n\n\n<li><strong>Frequency (\u03c9):<\/strong>\u00a0The output signal\u00a0y(t)\u00a0clearly oscillates at the same frequency as the input signal. The period\u00a0T\u00a0is approximately 3.14 seconds, so the frequency is\u00a0\u03c9 = 2\u03c0\/T = 2\u03c0\/\u03c0 = **2 rad\/s**.<\/li>\n\n\n\n<li><strong>Phase Shift (\u03b8):<\/strong>\u00a0The output\u00a0y(t)\u00a0is phase-shifted relative to the input\u00a0x(t). By measuring the time lag\u00a0\u0394t\u00a0between a peak of the input and the corresponding peak of the output, we find\u00a0\u0394t \u2248 0.095 s. The output peak occurs after the input peak, indicating a phase lag. The phase shift is calculated as\u00a0\u03b8 = -\u03c9 * \u0394t = -2 * 0.095 = **-0.19 rad**, or\u00a0<strong>-10.9 degrees<\/strong>.<\/li>\n<\/ol>\n\n\n\n<p>The following table compares these simulated values with the theoretical values calculated in part (c).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Parameter<\/td><td>Theoretical Value (Part c)<\/td><td>Simulated Value (from Plot)<\/td><\/tr><tr><td><strong>Amplitude (B)<\/strong><\/td><td>4.574 m<\/td><td>\u2248 4.57 m<\/td><\/tr><tr><td><strong>Frequency (\u03c9)<\/strong><\/td><td>2.0 rad\/s<\/td><td>2.0 rad\/s<\/td><\/tr><tr><td><strong>Phase Shift (\u03b8)<\/strong><\/td><td>-0.189 rad (-10.86\u00b0)<\/td><td>\u2248 -0.19 rad (-10.9\u00b0)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>As shown in the table, the amplitude, frequency, and phase shift determined from the MATLAB simulation align almost perfectly with the theoretically calculated values. The minor differences are negligible and can be attributed to the discretization of the time vector in the simulation and the precision of measuring values from the plot. The simulation successfully validates the analytical solution.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"1024\" src=\"https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/learnexams-banner8-1452.jpeg\" alt=\"\" class=\"wp-image-42612\" srcset=\"https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/learnexams-banner8-1452.jpeg 852w, https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/learnexams-banner8-1452-250x300.jpeg 250w, https:\/\/gaviki.com\/blog\/wp-content\/uploads\/2025\/06\/learnexams-banner8-1452-768x923.jpeg 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>) Use MATLAB using &#8220;lsim&#8221; command or &#8220;step&#8221; command. The quarter-car model of a vehicle suspension is shown in Figure 4.5.8a. In this simplified model, the masses of the wheel, tire, and axle are neglected, and the mass m represents one-fourth of the vehicle mass. The spring constant k models the elasticity of both the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-42610","post","type-post","status-publish","format-standard","hentry","category-quiz-questions"],"_links":{"self":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/42610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/comments?post=42610"}],"version-history":[{"count":1,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/42610\/revisions"}],"predecessor-version":[{"id":42613,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/posts\/42610\/revisions\/42613"}],"wp:attachment":[{"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/media?parent=42610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/categories?post=42610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaviki.com\/blog\/wp-json\/wp\/v2\/tags?post=42610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}