<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abdulrasheed Kamal on Medium]]></title>
        <description><![CDATA[Stories by Abdulrasheed Kamal on Medium]]></description>
        <link>https://medium.com/@abdulrasheedkamal40?source=rss-8353b82fd1f1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-r6jxvwYGODwIrkGRj5NIg@2x.jpeg</url>
            <title>Stories by Abdulrasheed Kamal on Medium</title>
            <link>https://medium.com/@abdulrasheedkamal40?source=rss-8353b82fd1f1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:55:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abdulrasheedkamal40/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Modelling and Simulation of 6G Network using MATLAB]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/modelling-and-simulation-of-6g-network-using-matlab-cfc1b02a37c5?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfc1b02a37c5</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Wed, 11 Dec 2024 08:52:34 GMT</pubDate>
            <atom:updated>2024-12-11T09:05:20.170Z</atom:updated>
            <content:encoded><![CDATA[<h2>MATLAB &amp; 6G TECHNOLOGY</h2><p>The evolution of wireless technology has brought us from the days of 2G text messages to the blazing-fast speeds of 5G. Now, researchers are setting their sights on 6G the sixth-generation wireless communication network. But what will 6G offer, and how can tools like MATLAB help us shape this revolutionary technology?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*k9zppK9pz88KgZ-_JvHeOw@2x.jpeg" /></figure><h3>What is 6G?</h3><p>6G is the next leap in wireless technology, expected to hit the market around 2030. While 5G focuses on high-speed internet and low latency, 6G will take communication to a whole new level by enabling futuristic applications like:</p><ol><li>Holographic communication: Imagine holding a virtual meeting where participants appear as lifelike holograms.</li><li>Smart cities and Internet of Everything (IoE): Seamless communication between billions of interconnected devices.</li><li>Remote surgeries: With near-zero latency, doctors can perform complex surgeries using robotic arms from miles away.</li><li>Space-based communication: Satellites integrated into 6G networks for global connectivity.</li></ol><p>To achieve these, 6G aims to utilize higher frequencies (like terahertz, THz), integrate artificial intelligence (AI) into communication systems, and provide unprecedented reliability and efficiency.</p><h3>Why MATLAB for 6G Research?</h3><p>MATLAB has been a cornerstone for engineers and researchers working on wireless technology. Its intuitive interface and extensive toolboxes make it ideal for modeling, simulation, and testing of communication systems. Here’s why MATLAB is perfect for 6G research:</p><ol><li>Quick Prototyping: MATLAB lets you design, test, and refine 6G algorithms in a single environment, reducing development time.</li><li>Accurate Simulation: With MATLAB, researchers can simulate real-world conditions like high-frequency channel modeling and massive MIMO (multiple-input multiple-output) systems.</li><li>AI Integration: MATLAB’s deep learning and AI capabilities help in designing intelligent 6G networks.</li></ol><h3>Key Areas of 6G Research in MATLAB</h3><p>1. Modeling Terahertz (THz) Communication Channels</p><p>6G will use the terahertz spectrum (0.1 – 10 THz), which offers incredible speeds but suffers from challenges like high path loss and limited range. MATLAB allows researchers to:</p><p>(a) Simulate THz propagation: Model how signals behave at terahertz frequencies, including reflections, absorption, and scattering.</p><p>(b) Design efficient antennas: Test antenna designs that overcome the limitations of THz communication.</p><blockquote>Example: MATLAB’s 5G Toolbox can be extended to simulate THz channel characteristics, helping researchers design robust systems for high-frequency communication.</blockquote><p>2. Massive MIMO and Beamforming</p><p>Massive MIMO involves using hundreds or even thousands of antennas to improve data rates and reliability. MATLAB helps you:</p><p>(a) Simulate massive MIMO systems: Evaluate performance in scenarios like crowded urban environments or high-speed trains.</p><p>(b) Develop advanced beamforming algorithms: Direct signals more effectively to specific users, reducing interference and power consumption.</p><p>3. AI-Powered Wireless Networks</p><p>6G networks will be intelligent, self-optimizing, and adaptive. MATLAB’s Deep Learning Toolbox and Reinforcement Learning Toolbox allow researchers to:</p><ul><li>Design machine-learning algorithms for dynamic resource allocation.</li><li>Simulate AI-based communication protocols that adjust to changing conditions in real time.</li><li>Optimize energy efficiency in ultra-dense networks.</li></ul><p>4. Holographic Communication</p><p>Holographic communication requires ultra-low latency and high-speed data transfer. MATLAB can simulate the bandwidth and delay requirements for holographic data, ensuring that networks can handle these futuristic applications.</p><p>5. Energy-Efficient Communication</p><p>With billions of devices connected in 6G, energy efficiency is critical. MATLAB can help design and simulate energy-saving protocols, reducing the environmental impact of massive data transmission.</p><h3>Building a 6G Prototype in MATLAB</h3><p>Here’s a step-by-step example of how MATLAB can be used to prototype a 6G communication system:</p><ol><li>Channel Modeling: Use MATLAB to simulate a terahertz communication channel with multiple reflectors and obstacles.</li></ol><pre>freq = 1e12; % Frequency in Hz (1 THz)<br>d = 1; % Distance in meters<br>pathLoss = 20*log10(freq) + 20*log10(d) - 147.55;<br>disp([‘Path Loss at 1 THz: ‘, num2str(pathLoss), ‘ dB’]);</pre><p>2. Waveform Design:</p><p>Develop an advanced waveform like OTFS (Orthogonal Time Frequency Space) that performs well in high-mobility scenarios.</p><p>3. Massive MIMO Simulation:</p><p>Simulate a system with 256 antennas and test its performance under different environmental conditions.</p><p>4. AI-Based Optimization:</p><p>Use reinforcement learning to dynamically allocate bandwidth and power in a dense network.</p><p>5. Performance Analysis:</p><p>Plot the bit error rate (BER) and throughput to evaluate the system’s reliability and speed.</p><h4>6G Satellites: LEO and HEO</h4><p>To support global 6G networks, satellites play a crucial role in expanding coverage and providing connectivity in remote areas. The two most likely orbits for 6G satellites are:</p><p>Low Earth Orbit (LEO)</p><p>• Primary Choice for 6G Satellites: Most 6G satellite networks are expected to operate in LEO, typically at altitudes between 500 and 2,000 km.</p><p>Advantages:</p><ol><li>Low Latency: Minimal signal delay, essential for real-time applications like holographic communication and autonomous vehicles.</li><li>High Throughput: Supports high-speed internet and seamless global connectivity.</li><li>Dense Constellations: LEO satellites work in constellations to provide continuous global coverage.</li></ol><h4>Highly Elliptical Orbit (HEO)</h4><p>HEO satellites are ideal for covering high-latitude regions like the Arctic and Antarctic.</p><p>Advantages:</p><p>1. Extended Coverage: Spend more time over specific regions, enhancing connectivity in areas where LEO constellations might be sparse.</p><p>2. Complementary Role: HEO satellites can work alongside LEO networks for broader coverage.</p><p>Generally speaking;</p><p>6G technology promises to revolutionize how we connect, communicate, and interact with the world. With MATLAB, researchers and engineers have a powerful tool to bring this vision to life. Whether it’s designing terahertz communication systems, building AI-driven networks, or creating energy-efficient protocols, MATLAB empowers us to shape the future of wireless technology.</p><p>As we stand on the brink of the 6G era, the possibilities are endless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*XmrWfKiFEBkzHChtZo-lvA@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfc1b02a37c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Partial Differential Equations with MATLAB]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/partial-differential-equations-with-matlab-6787d910ecbd?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6787d910ecbd</guid>
            <category><![CDATA[science]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[math]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Fri, 20 Sep 2024 17:59:28 GMT</pubDate>
            <atom:updated>2024-09-20T21:03:47.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Comprehensive Guide to Finite Element, Finite Difference, and Separation of Variable Methods</h3><p><strong><em>Laplacian equation is used as an example in this article.</em></strong></p><h4>Finite Difference Method (FDM)</h4><p><strong>step 1</strong></p><pre>%clear workspace and command windows<br>clear;<br>clc;</pre><p>clear; remove any existing variables in the workspace to avoid conflict. clc clears the command window for a fresh display of output.</p><p><strong>Step 2</strong></p><p>Defining the grid and parameters</p><pre>%define the grid and parameters<br>n = 20; % for internal points in x and y direction<br>a = 0; b = 1; % x-domain [a, b]<br>c =  0; d = 1; % y-domain [c, d]</pre><p>n = 20 specifies that there are 20 internal points in both x and y directions (excluding the boundaries).</p><p>the domain of the problem is defined as a square ranging from a = 0 to b =1, and y ranging from c = 0 to d = 1</p><p><strong>Step 3</strong></p><p>Calculating the step size</p><pre>%step size <br>dx = (b-a)/(n+1); % step size in x-direction<br>dy = (d-c)/(n+1); %step size in y-direction</pre><p>dx and dy are distances between the grid points in the x &amp; y directions respectively</p><p><strong>Step 4</strong></p><p>Creating the Grid</p><pre>%Create grid<br>x = linespace(a, b, n+2); % include the boundary points<br>y = linespace(c, d, n+2); % &quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot;</pre><p>linespace (a, b, n+1) generates n+1 equal-spaced points from a to b</p><p><strong>Step 5</strong></p><p>Initializing the Solution Matrix</p><pre>%Initialize solution matrix<br>U = zeros(n+2, n+2);</pre><p>A matrix of size (n+2) by (n+2) is initialized to store the solution at each grid point</p><p><strong>Step 6</strong></p><p>Applying the boundary points</p><pre>%Apply the boundary points<br>%buttom boundary: u(x. 0) = x<br>u(1, :0); = x % bottom row corresponds to y = 0<br><br>%Top boundary u(x, 1); = 0<br>u(end, :) = 0;<br><br>%left boundary u(0, y) = 0<br>u(:, 1) = 0;<br><br>%Right boundaries u(1, y) = 2*y<br>u(:, end) = 2*y;</pre><p><strong>Step 7</strong></p><p>Define the Finite Difference Coefficients</p><pre>%Finite difference coefficients<br>alpha = 1/dx^2<br>beta = 1/dy^2<br>gamma = -2*(alpha + beta);</pre><p>alpha =coefficients of the second derivatives wrt x</p><p>beta = coefficients of the second derivatives wrt y</p><p>gamma = coefficients of a center point in the finite difference stencils which combines both x and y</p><p><strong>step 8</strong></p><p>Assembling the Systems of equation</p><pre>%assemble the system of linear equations<br>  A = zero(n*n, n*n) % Coefficient matrix<br>F= zeros(n*n, 1); %Right-Hand side vector</pre><p>A is the coefficient matrix for the linear for the linear system, while F is the right-hand side vector of the linear systems</p><p><strong>Step 9</strong></p><p>Filling the coefficients and Right-Hand Side Vector</p><pre>for j = 1:n<br>   for i = 1:n<br>% global index for the point(i, j)<br>       k = (j-1)*n +1;<br> %Fill the coefficients in matrix A<br>       A(k,k) = gamma; %%center coeficients<br>       if i&gt;1 % left neighbour<br>           A(k, k-1) = alpha;<br>       end<br>       if i&lt;n  % Right neighbour<br>          A(k, k+1) = alpha;<br>       end<br>      if j&gt; 1 %Buttom neighbour<br>          A(k, k-n) = beta;<br>       end<br>      if j,n   %Top neighbor<br>       A(k, k+n) = beta;<br>      end</pre><p>for each internal point (i, j) the corresponding global index is calculated</p><p>the coefficients for the finite difference stencil are placed in matrix A</p><p><strong>Step 10</strong></p><p>Modifying the Right-Han side vector for boundary conditions</p><pre>%%%%%fill the right_hand side vector F<br>F(k) = 0;<br>%modify F to include contributions from boundary conditions<br>  <br>if j ==1 <br>    F(k) = F(k)- alpha* U(1, i+1);<br>end<br>if j ==n F(k) - alpha*U(end, i+1);<br>end<br>if i ==1<br>      F(k) - beta*U(j+1, 1);<br>end<br>if i==n <br>      F(k) - beta*U(j+1, end);<br>   end<br> end<br>end<br></pre><p>F(k) is modified based on contributions from Boundary conditions;</p><p>for each boundary, the corresponding values are subtracted from F</p><p><strong>Step 11</strong></p><p>Solve the systems of equation</p><pre>%%%solve the linear systems<br><br>U_internal = A\F;</pre><p>The systems A*U_internal = F s the solution</p><p><strong>Step 12</strong></p><p>Plotting the solution</p><pre>%%%% Plot the solutions<br>[X,Y] =Meshgrid(x,y)<br>figure<br>surf(X,Y, U&#39;);<br>xlabel(&#39;x&#39;)<br>ylabel(&#39;y&#39;);<br>zlabel (&#39;u(x,y)<br>tite (&#39;Finite difference Method Solution&#39;);<br></pre><p>The solution is visualized as a 3D surface plot using surf. The mesh gridX and Y are created from the grid point</p><p>The full code is;</p><pre>% Clear workspace and a command window<br>clear;<br>clc;<br><br>% Define the grid and parameters<br>n = 20; % Number of internal points in x and y directions<br>a = 0; b = 1; % x-domain [a,b]<br>c = 0; d = 1; % y-domain [c,d]<br><br>% Step sizes<br>dx = (b - a) / (n + 1); % Step size in x-direction<br>dy = (d - c) / (n + 1); % Step size in y-direction<br><br>% Create grid<br>x = linspace(a, b, n+2); % Include boundary points<br>y = linspace(c, d, n+2); % Include boundary points<br><br>% Initialize solution matrix<br>U = zeros(n+2, n+2);<br><br>% Apply boundary conditions<br>% Bottom boundary: u(x,0) = x<br>U(1, :) = x; % Bottom row corresponds to y = 0<br><br>% Top boundary: u(x,1) = 0<br>U(end, :) = 0; % Top row corresponds to y = 1<br><br>% Left boundary: u(0,y) = 0<br>U(:, 1) = 0; % Left column corresponds to x = 0<br><br>% Right boundary: u(1,y) = 2*y<br>U(:, end) = 2*y; % Right column corresponds to x = 1<br><br>% Finite difference coefficients<br>alpha = 1 / dx^2;<br>beta = 1 / dy^2;<br>gamma = -2 * (alpha + beta);<br><br>% Assemble the system of linear equations<br>A = zeros(n*n, n*n);<br>F = zeros(n*n, 1);<br><br>for j = 1:n<br>    for i = 1:n<br>        % Global index for the point (i,j)<br>        k = (j-1)*n + i;<br><br>        % Fill the coefficients in matrix A<br>        A(k, k) = gamma; % Center coefficient<br><br>        if i &gt; 1 % Left neighbor<br>            A(k, k-1) = alpha;<br>        end<br>        if i &lt; n % Right neighbor<br>            A(k, k+1) = alpha;<br>        end<br>        if j &gt; 1 % Bottom neighbor<br>            A(k, k-n) = beta;<br>        end<br>        if j &lt; n % Top neighbor<br>            A(k, k+n) = beta;<br>        end<br><br>        % Fill the right-hand side vector F<br>        F(k) = 0;<br><br>        % Modify F to include contributions from boundary conditions<br>        if j == 1 % Bottom boundary (y = 0)<br>            F(k) = F(k) - alpha * U(1, i+1);<br>        end<br>        if j == n % Top boundary (y = 1)<br>            F(k) = F(k) - alpha * U(end, i+1);<br>        end<br>        if i == 1 % Left boundary (x = 0)<br>            F(k) = F(k) - beta * U(j+1, 1);<br>        end<br>        if i == n % Right boundary (x = 1)<br>            F(k) = F(k) - beta * U(j+1, end);<br>        end<br>    end<br>end<br><br>% Solve the linear system A*U_internal = F<br>U_internal = A \ F;<br><br>% Reshape the solution into a matrix form<br>U(2:end-1, 2:end-1) = reshape(U_internal, n, n);<br><br>% Plot the solution<br>[X, Y] = meshgrid(x, y);<br>figure;<br>surf(X, Y, U&#39;);<br>xlabel(&#39;x&#39;);<br>ylabel(&#39;y&#39;);<br>zlabel(&#39;u(x,y)&#39;);<br>title(&#39;Finite Difference Method Solution&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*1CdKvlOnIwzZeJOM3UH1cw@2x.jpeg" /></figure><h4><strong>FINITE ELEMENT METHOD (FEMs)</strong></h4><p><strong>Step 1</strong></p><p>clear the workspace and Command window</p><pre>%clear workspace and command window<br>clear;<br>clc;</pre><p><strong>step 2</strong></p><pre>%Define the number of elements along x and y direction<br>n_elem_x = 3; %Number of elements along the x-direction<br>n_elem_y = 3; %Number of elements along  the y-direction</pre><p>here, the domain is divided into 3*3 grid elements, resulting in a total of 9 elements</p><p><strong>step 3</strong></p><p>Setting Domain Boundaries</p><pre>%domain boundaries<br>a = 0; b= 1;   %x-domain<br>c = 0; d = 1;   % y-domain</pre><p><strong>step 4</strong></p><p>Define the Number of Nodes</p><pre>%number of nodes along x and y directions<br>n_node_x = n_elem_x +1;<br>n_node_y = n_elem_y +1;</pre><p>Each element is defined by its corner nodes. Therefore if there are 3 elements along the x-direction, there will be 4 nodes ( n_elem_x+1)</p><p><strong>Step 5</strong></p><p>Generating The Mesh Grid</p><pre>%Generate the mesh grid of nodes<br>x = linespace(a, b, n_nodes_x);<br>y = linespace(c, d, n_nodes_y);</pre><p><strong>Step 6</strong></p><p>Initializing Global Stiffness Matrix and Force Vector</p><pre>%Initialize the global stiffness matrix and force vector<br><br>K = zeros(n_nodes_x*n_nodes_y, n_nodes_x*n_nodes_y);<br>F = zeros(n_nodes_x*n_nodes_y, 1);</pre><p>where K is the global stiffness matrix, initialized to zero. Its size corresponds to the total number of nodes ( n_nodes_x* n_nodes_y) F is the global force vector, also initialized to zero</p><p><strong>Step 7</strong></p><p>Assembling the Global Stiffness Matrix</p><pre>for j = 1:n_elem_y<br>  for i = 1:n_elem_x<br>     %Node of the element(i,j)<br>     n1 = (j-1)*n_nodes_x+i;<br>     n2 = (j-1)*n_nodes_x+(i+1);<br>     n3 = j*n_nodes_x+(i+1);<br>     n4 = j*n_nodes_x+i;<br><br>%%local stiffness matrix for the elements<br><br>   Ke = 1/6 * [ 2 -2 -1 1;<br>               -2 2 1 -1;<br>                -1 1 2 -2;<br>                1 -1 -2 2];<br><br>% Add local stiffness matrix  to global matrix<br>    <br>  local_node = [n1, n2, n3, n4]<br>   for ii = 1:4<br>     for jj = 1:4<br>     K(local_node(ii), local_nodes(jj)) = ...<br>        K(local_node(ii), local_nodes(jj)+Ke(ii, jj);<br>         end<br>      end<br>   end<br>end</pre><p>This loop goes over all the elements in the grid. For each element, it identifies its four corner nodes (n1, n2, n3, n4)</p><p>Ke is the local stiffness matrix for a 4-node quadrilateral element, derived from the FEM theory. The local stiffness matrix is then added to the global stiffness matrix K for each node</p><p><strong>Step 8</strong></p><p>Applying Boundary Conditions</p><pre>for i = 1:n_nodes_x<br>  %bottom boundary (y = 0)<br>  F(i) = x(i); %u(x, 0) = x<br>   K(i, :) = 0 %Rest row i of K<br>   K(i, i) = 1 %Impose Dirichlets condition at this node</pre><p>This loop applies the Dirichlet boundary conditions which specify the solution u at the boundary</p><pre>%Top boundary (y = 1)<br>top_idx = (n_nodes_y-1)*n_nodes_x + i;<br> F(top_idx) = 0  %u(x, 1) = 0<br> K(top_idx, :) = 0;<br> K(top_idx, top_idx) =1;</pre><p>Similar conditions are applied for the<strong> left(x = 0)</strong> and <strong>right(x = 1)</strong></p><pre>%keft boundary (x =0)<br>F(left_idx) = 0;<br>K(left_idx, left_idx) =1;<br>K(left_idx, left_idx) =1;<br><br>%right boundary (x =1)<br>F(right_idx) = 2*y(j+1);<br>K(right_idx, :) = 0;<br>K(right_idx, right_idx) = 1;</pre><p><strong>Step 9</strong></p><pre>%Solve the linear systems K*U = F<br>U = K\F;</pre><p>The system of linear equation K*U =F is solved, where U is the vector of unknown nodal values</p><p><strong>Step 10</strong></p><p>Reshaping the Solution and Visualization</p><pre>%Reshape the solution into the matrix to visualize the solution<br>U_matrix = reshape(U, n_nodes_x, n_nodes_y)&#39;;<br><br>%Display the solution as a surface plot<br>[X, Y] = meshgrid(x, y);<br>figure;<br>surf(X, Y, U_matrix);<br>xlabel(&#39;x&#39;);<br>ylabel(&#39;y&#39;);<br>zlabel(&#39;u(x,y)&#39;);<br>title(&#39;finite Element Method Solution&#39;);</pre><p>The solution U is reshaped into a matrix for easy visualization.</p><p>surf(X, Y, U_matrix) creates a 3D surface plot of the solution, where X and Y are the grid points, and U_matrix contains the solution values.</p><p>The Full code is;</p><pre>% Clear workspace and a command window<br>clear;<br>clc;<br><br>% Define the number of elements along x and y directions<br>n_elem_x = 3;  % Number of elements along the x-direction<br>n_elem_y = 3;  % Number of elements along y-direction<br><br>% Domain Boundaries<br>a = 0; b = 1;  % x-domain [a,b]<br>c = 0; d = 1;  % y-domain [c,d]<br><br>% Number of nodes along x and y directions<br>n_nodes_x = n_elem_x + 1;<br>n_nodes_y = n_elem_y + 1;<br><br>% Generate the mesh grid of nodes<br>x = linspace(a, b, n_nodes_x);<br>y = linspace(c, d, n_nodes_y);<br><br>% Initialize the global stiffness matrix and force vector<br>K = zeros(n_nodes_x * n_nodes_y, n_nodes_x * n_nodes_y);<br>F = zeros(n_nodes_x * n_nodes_y, 1);<br><br>% Assemble the global stiffness matrix and force vector<br>for j = 1:n_elem_y<br>    for i = 1:n_elem_x<br>        % Nodes of the element (i,j)<br>        n1 = (j-1)*n_nodes_x + i;<br>        n2 = (j-1)*n_nodes_x + (i+1);<br>        n3 = j*n_nodes_x + (i+1);<br>        n4 = j*n_nodes_x + i;<br>        <br>        % Local stiffness matrix for the element<br>        % Standard FEM local stiffness matrix for a 4-node quadrilateral element<br>        Ke = 1/6 * [2 -2 -1 1; -2 2 1 -1; -1 1 2 -2; 1 -1 -2 2];<br>        <br>        % Add local stiffness matrix to global matrix<br>        local_nodes = [n1, n2, n3, n4];<br>        for ii = 1:4<br>            for jj = 1:4<br>                K(local_nodes(ii), local_nodes(jj)) = ...<br>                    K(local_nodes(ii), local_nodes(jj)) + Ke(ii, jj);<br>            end<br>        end<br>    end<br>end<br><br>% Apply boundary conditions (e.g., u(x,0) = x, u(x,1) = 0, etc.)<br>for i = 1:n_nodes_x<br>    % Bottom boundary (y = 0)<br>    F(i) = x(i); % u(x,0) = x<br>    K(i, :) = 0; % Reset row i of K<br>    K(i, i) = 1; % Impose Dirichlet condition at this node<br><br>    % Top boundary (y = 1)<br>    top_idx = (n_nodes_y-1)*n_nodes_x + i;<br>    F(top_idx) = 0; % u(x,1) = 0<br>    K(top_idx, :) = 0; % Reset row top_idx of K<br>    K(top_idx, top_idx) = 1; % Impose Dirichlet condition at this node<br>end<br><br>for j = 0:n_nodes_y-1<br>    % Left boundary (x = 0)<br>    left_idx = 1 + j*n_nodes_x;<br>    F(left_idx) = 0; % u(0,y) = 0<br>    K(left_idx, :) = 0; % Reset row left_idx of K<br>    K(left_idx, left_idx) = 1; % Impose Dirichlet condition at this node<br>    <br>    % Right boundary (x = 1)<br>    right_idx = n_nodes_x + j*n_nodes_x;<br>    F(right_idx) = 2*y(j+1); % u(1,y) = 2*y<br>    K(right_idx, :) = 0; % Reset row right_idx of K<br>    K(right_idx, right_idx) = 1; % Impose Dirichlet condition at this node<br>end<br><br>% Solve the linear system K*U = F<br>U = K \ F;<br><br>% Reshape solution into a matrix to visualize the solution on the grid<br>U_matrix = reshape(U, n_nodes_x, n_nodes_y)&#39;;<br><br>% Display the solution as a surface plot<br>[X, Y] = meshgrid(x, y);<br>figure;<br>surf(X, Y, U_matrix);<br>xlabel(&#39;x&#39;);<br>ylabel(&#39;y&#39;);<br>zlabel(&#39;u(x,y)&#39;);<br>title(&#39;Finite Element Method Solution&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*moJ_-q5gZmaCjwwhAPiDfQ@2x.jpeg" /></figure><h4>METHOD OF SEPARATING VARIABLES</h4><p>We assumed that the solution can be written as a product of two functions</p><p><strong><em>u(x, y) = X(x) • Y(y)</em></strong></p><p>Substituting this into the Laplacian equation gives</p><p><strong><em>X”(x) Y(y) + X(x) Y”(y) = 0</em></strong></p><p>This separates the equation into two ordinary differential equations</p><ol><li><strong><em>X”(x) + kX(x) = 0</em></strong></li><li><strong><em>Y”(y) – KY(y) = 0</em></strong></li></ol><p>Where k is the separating constant</p><h4>Step by step on MATLAB computations</h4><p><strong>Step 1</strong></p><p>Clear workspace and a command window</p><pre>% Clear workspace and a command window<br>clear;<br>clc;</pre><p><strong>Step 2</strong></p><p>Define the domain of the boundaries</p><pre>% Define the boundary of the domain<br><br>a = 0; b = 1; % x-domain [a,b]<br>c = 0; d = 1; % y-domain [c,d]</pre><p>Here, we define the rectangular domain where x ranges from 0 to 1, y ranges from 0 to 1.</p><p><strong>Step 3</strong></p><p>Set the number of times in the Fourier series</p><pre>% Define the number of terms in the series (accuracy)<br><br>N = 20; % Number of terms in the Fourier series expansion</pre><p>The separation of variables involves a Fourier series solution. The more terms (N = 20)we include, the more the approximation becomes.</p><p><strong>Step 4</strong></p><p>Create a grid for plotting solutions</p><pre>% Create the grid for the domain<br><br>n_points = 50; % Number of points for x and y<br>x = linspace(a, b, n_points);<br>y = linspace(c, d, n_points);<br>[X, Y] = meshgrid(x, y);</pre><p>This generates a mesh grid for the <strong><em>x</em></strong> and <strong><em>y</em></strong> values. Here, we are creating a 50 by 50 grid for visualization.</p><p>Meshgrid creates two matrices X and Y that hold the values of <strong><em>x</em></strong> and <strong><em>y</em></strong> coordinate at each point.</p><p><strong>Step 5</strong></p><p>Initialize the Solution</p><pre>% Initialize the solution matrix<br><br>U = zeros(n_points, n_points);</pre><p>The solution matrice U is initialized to store the values of <strong><em>u(x, y) </em></strong>at each grid point</p><p><strong>Step 6</strong></p><p>Solve the Fourier Series</p><pre>% Loop over Fourier series terms<br>for m = 1:N<br>    for n = 1:N<br>        % Separation of variables solution<br>        % X(x) = sin(m*pi*x), Y(y) = sinh(n*pi*y)<br>        <br>        % Coefficient for the Fourier series (This is typically determined<br>        % by the initial or boundary conditions, we&#39;ll assume C_mn = 1 for simplicity)<br>        C_mn = 1; % Assume unit coefficient<br>        <br>        % Calculate each term of the series<br>        U = U + C_mn * sin(m*pi*X) .* sinh(n*pi*Y) / sinh(n*pi*d);<br>    end<br>end</pre><p>The key idea behind the separation of variables is that the solution is written as the product of <strong><em>sine</em></strong> <strong><em>and hyperbolic sine</em></strong></p><p>For each term of the Fourier series ( summation over <em>m</em> and <em>n</em> ), we compute the corresponding term using</p><p><strong><em>X(x) = sin(mπx)</em></strong></p><p><strong><em>Y(y) = sinh(nπy</em></strong>)</p><p>The coefficient C_mn​ is determined by the initial conditions, but in this context, we assume it to be 1.</p><p>Step 7</p><p>Plot the solution</p><pre>% Plot the solution<br><br>figure;<br>surf(X, Y, U);<br>xlabel(&#39;x&#39;);<br>ylabel(&#39;y&#39;);<br>zlabel(&#39;u(x,y)&#39;);<br>title(&#39;Solution to Laplace Equation via Separation of Variables&#39;);</pre><p>The complete code is</p><pre>% Clear workspace and a command window<br>clear;<br>clc;<br><br>% Define the boundary of the domain<br>a = 0; b = 1; % x-domain [a,b]<br>c = 0; d = 1; % y-domain [c,d]<br><br>% Define the number of terms in the series (accuracy)<br>N = 20; % Number of terms in the Fourier series expansion<br><br>% Create the grid for the domain<br>n_points = 50; % Number of points for x and y<br>x = linspace(a, b, n_points);<br>y = linspace(c, d, n_points);<br>[X, Y] = meshgrid(x, y);<br><br>% Initialize the solution matrix<br>U = zeros(n_points, n_points);<br><br>% Solution to Laplace&#39;s equation using separation of variables<br>% Apply Fourier Series with sine functions satisfying boundary conditions<br><br>% Loop over Fourier series terms<br>for m = 1:N<br>    for n = 1:N<br>        % Separation of variables solution<br>        % X(x) = sin(m*pi*x), Y(y) = sinh(n*pi*y)<br>        <br>        % Coefficient for the Fourier series (This is typically determined<br>        % by the initial or boundary conditions, we&#39;ll assume C_mn = 1 for simplicity)<br>        C_mn = 1; % Assume unit coefficient<br>        <br>        % Calculate each term of the series<br>        U = U + C_mn * sin(m*pi*X) .* sinh(n*pi*Y) / sinh(n*pi*d);<br>    end<br>end<br><br>% Plot the solution<br>figure;<br>surf(X, Y, U);<br>xlabel(&#39;x&#39;);<br>ylabel(&#39;y&#39;);<br>zlabel(&#39;u(x,y)&#39;);<br>title(&#39;Solution to Laplace Equation via Separation of Variables&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*LhR-RQjFsTcBDYN5xZMW_A@2x.jpeg" /></figure><h3>Boundary and Initial Valued Problems</h3><p>In this particular code, we focused on the boundary values problems, where the solution must satisfy specific conditions on the boundary of the domain.</p><p>Suppose you’re solving an Initial valued problem, the approach would involve time-dependent terms which typically require solving heat or wave equations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6787d910ecbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DIFFERENTIAL EQUATIONS WITH MATLAB]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/differential-equations-with-matlab-b5444e682124?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5444e682124</guid>
            <category><![CDATA[math]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Sun, 25 Aug 2024 07:20:29 GMT</pubDate>
            <atom:updated>2024-08-25T11:06:20.354Z</atom:updated>
            <content:encoded><![CDATA[<p>Differential equations are fundamental tools in modeling, playing a significant role in various fields like physics, economics, engineering, and biology. Differential equations describe the behavior of function and its derivatives capturing the dynamics of systems that change over time.</p><p>MATLAB on the other hand provides robust tools for solving DE numerically, being it simple first-order or more advanced higher-order.</p><p>This article will guide you through the process of solving differential equations in varying orders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*V2L_jfqi7XSH3dOpf0eZ6w@2x.jpeg" /></figure><h4>FIRST ORDER DIFFERENTIAL EQUATIONS</h4><p>Suppose we’re to solve y’ + y = exp(-t)</p><p>Such that: y(0) = 1</p><p>Step 1: Define the differential equation</p><pre>%%MATLAB<br>dydt = @(t,y) -y + exp(-t);</pre><p>Here, dydt is the function that represents the DE. We must make dy/dt the subject of the formula. The @(t,y) creates an anonymous variables that represent t, y</p><p>Step 2: Specify the initial conditions and period.</p><pre>%%Matlab<br>y(0) = 1; %%% Initial condition <br>tspan[0 5];  %%% time interval from 0 to 5 sec</pre><p>Step 3: Define the ode solver.</p><p>Matlab has several built-in ode solvers like ode15, ode23, ode45. We call any of these functions to get the numerical solution</p><pre>%%Matlab<br>[t, y] = ode45(dydt, tspan, y(0));</pre><p>‘‘t’’ is the time point, ‘‘y’’ is the solution corresponding to each time.</p><p>Step 4: Plot the Solution</p><pre>plot(t, y, &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solution y(t)&#39;);<br>title(&#39;Solution of First-Order DE using ode45&#39;);<br>grid on;</pre><p>This will plot y(t)</p><p>The output graph will be displayed, we can adjust the span or refine the plots needed.</p><p>The full code is</p><pre>% Define the differential equation<br>dydt = @(t, y) -y + exp(-t);<br><br>% Initial condition and time span<br>y(0) = 1;           <br>tspan = [0 5];   <br><br>% Solve the DE using ode45<br>[t, y] = ode45(dydt, tspan, y0);<br><br>% Plot the solution<br>plot(t, y, &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solution y(t)&#39;);<br>title(&#39;Solution of First-Order DE using ode45&#39;);<br>grid on;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*s4ePh9XZ8F4xji9AMSqg-Q@2x.jpeg" /></figure><h3>SECOND ORDER DIFFERENTIAL EQUATION</h3><p>Suppose we’re to solve</p><p>d²y/dt² + 5 dy/dt + 6y = 0</p><p>y(0) = 1 and y’(1) = 2</p><h4>Step 1: We convert the second order DE into systems of first order DE</h4><p>Let y = y₁</p><p>dy/dt = y₂</p><p>dy₁/dt. = y₂ — — — — (1)</p><p>So, d²y/dt² = dy₂/dt</p><p>Therefore; dy₂/dt + 5y₂ + 6y₁ = 0</p><p>dy₂/dt = -5y₂ − 6y₁. — — — — (2)</p><p>Step 3: Define the system of first-order DEs</p><p>We can define the system of DEs using a function handle or separate function file</p><pre>dydt = @(t, Y) [Y(2); -5*Y(2) - 6*Y(1)];</pre><p>Y(1) represents y₁ = y</p><p>Y(2) represents y₂ = dy/dt</p><p>Step 4: Specify the initial conditions</p><pre>Y0 = [1; 2];  %%Initial conditions: y(0) = 1, dy/dt(1) = 2<br>tspan = [0 10];  % %Time interval from t = 0 to t = 10</pre><p>Step 5: Solve the system using ode solver</p><pre>[t, Y] = ode45(dydt, tspan, Y0);</pre><p>t is the vector of time. Y is an array where each column is the solution of y₁ and y₂</p><p>Step 6: Extract and plot the Solution</p><pre>% Plot both y1(t) and y2(t) on the same graph<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the System of First-Order DEs&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;);<br>grid on;</pre><p>This plots the two solutions y₁ and y₂ over time t</p><p>The full code is</p><pre>%%Matlab<br><br>% Define the system of first-order DEs<br>dydt = @(t, Y) [Y(2); -5*Y(2) - 6*Y(1)];<br><br>% Initial conditions and time span<br>Y0 = [1; 2];  % y(0) = 1, dy/dt(1) = 2<br>tspan = [0 10];  % Time interval from t = 0 to t = 10<br><br>% Solve the DE using ode45<br>[t, Y] = ode45(dydt, tspan, Y0);<br><br>% Plot both y1(t) and y2(t) on the same graph<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the System of First-Order DEs&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;);<br>grid on;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*7bV1NiV-Q_qxfSyhHi58wg@2x.jpeg" /></figure><p>Another example;</p><p>Suppose we’re to solve a non-homogeneous equation</p><p>d²y/dt² + 3dy/dt + 2y = sin(2t)</p><p>Such that y(0) = 1 and y’(0) = 0</p><p>Step 1: Convert the DE into a System of first-order DEs</p><p>Let y = y₁</p><p>dy₁/dt = y₂. — — — -(1)</p><p>d²y/ dt² = dy₂/ dt</p><p>Therefore;</p><p>dy₂/dt + 3y₂ + 2y₁ = sin(2t)</p><p>dy₂/dt = -3y₂ — 2y₁ + sin(2t) — — — (2)</p><p>Step 3: Define the systems of DEs in Matlab</p><pre>dydt = @(t, Y) [Y(2); -3*Y(2) - 2*Y(1) + sin(2*t)];</pre><p>Y(1) represents y₁</p><p>Y(2) represents y₂ = dy/dt</p><p>Step 4: Set the Initial conditions and Timespan</p><pre>Y0 = [1; 0];      % Initial conditions: y(0) = 1, dy/dt(0) = 0<br>tspan = [0 10];   % Time interval from t = 0 to t = 10</pre><p>Step 5: Solve the system using ode solver</p><pre>[t, Y] = ode45(dydt, tspan, Y0);</pre><p>t is the vector of time points</p><p>Y is an array where each row corresponds to the solution of vector y₁ and y₂</p><p>Step 6: Plot the Solutions</p><pre>% Plot both y1(t) and y2(t) on the same graph<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the System of First-Order DEs&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;);<br>grid on;</pre><p>The full code is</p><pre>%Matlab<br>% Define the system of first-order DEs<br>dydt = @(t, Y) [Y(2); -3*Y(2) - 2*Y(1) + sin(2*t)];<br><br>% Initial conditions and time span<br>Y0 = [1; 0];        % y(0) = 1, dy/dt(0) = 0<br>tspan = [0 10];     % Time interval from t = 0 to t = 10<br><br>% Solve the DE using ode45<br>[t, Y] = ode45(dydt, tspan, Y0);<br><br>% Plot both y1(t) and y2(t) on the same graph<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the System of First-Order DEs&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;);<br>grid on;</pre><p>Suppose we are to visualize and analyze each solution separately from the graph we use the subplot function</p><pre>% Plot y(t) on the first subplot<br>subplot(2,1,1);<br>plot(t, Y(:,1), &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;y(t)&#39;);<br>title(&#39;Solution y(t) vs Time&#39;);<br>grid on;<br><br>% Plot dy/dt(t) on the second subplot<br>subplot(2,1,2);<br>plot(t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;dy/dt(t)&#39;);<br>title(&#39;Solution dy/dt(t) vs Time&#39;);<br>grid on;</pre><p>The full code with both plotting options is</p><pre>%%Matlab<br><br>% Define the system of first-order DEs<br>dydt = @(t, Y) [Y(2); -3*Y(2) - 2*Y(1) + sin(2*t)];<br><br>% Initial conditions and time span<br>Y0 = [1; 0];        % y(0) = 1, dy/dt(0) = 0<br>tspan = [0 10];     % Time interval from t = 0 to t = 10<br><br>% Solve the DE using ode45<br>[t, Y] = ode45(dydt, tspan, Y0);<br><br>% Option 1: Plot both y(t) and dy/dt(t) on the same graph<br>figure;<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the System of First-Order DEs&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;);<br>grid on;<br><br>% Option 2: Plot y(t) and dy/dt(t) on separate subplots<br>figure;<br>subplot(2,1,1);<br>plot(t, Y(:,1), &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;y(t)&#39;);<br>title(&#39;Solution y(t) vs Time&#39;);<br>grid on;<br><br>subplot(2,1,2);<br>plot(t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;dy/dt(t)&#39;);<br>title(&#39;Solution dy/dt(t) vs Time&#39;);<br>grid on;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*XB3EDpOBZnHrrhkWeuXMuA@2x.jpeg" /></figure><h4>THIRD ORDER DIFFERENTIAL EQUATION</h4><p>Suppose we’re to solve</p><p>y”’ – 3y” + 2y’ – y’ = cos(t)</p><p>Such that y(0) = 1, y’(0) = 0 and y”(0) = 1</p><p>Step 1: convert the equation into systems of first-order DEs</p><p>Let y = y₁</p><p>dy/dt = y₂</p><p>d²y/dt² = y₃</p><p>Therefore dy₃/dt = 3y₃ – 2y₂ + y₁ + cos(t)</p><p>Step 2: Define the system of DEs in Matlab</p><pre>dydt = @(t, Y) [Y(2); Y(3); 3*Y(3) - 3*Y(2) + Y(1) + cos(t)];</pre><p>Y(1) represents y₁</p><p>Y(2) represents y₂ = dy/dt</p><p>Y(3) represents y₃ = d²y/dt²</p><p>Step 3: Set the initial conditions and timespan</p><pre>Y0 = [1; 0; 0];  % Initial conditions: y(0) = 1, dy/dt(0) = 0, d^2y/dt^2(0) = 0<br>tspan = [0 10];  % Time interval from t = 0 to t = 10</pre><p>Step 4: Solve the system using Ode solver</p><pre>[t, Y] = ode45(dydt, tspan, Y0);</pre><p>t is a vector of time points</p><p>Y is an array of solutions of y₁ and y₂</p><p>Step 5: Plot the solution</p><p>Here we’re plotting the solution separately using subplot function</p><pre>figure;<br>subplot(3,1,1);<br>plot(t, Y(:,1), &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;y(t)&#39;);<br>title(&#39;Solution y(t) vs Time&#39;);<br>grid on;<br><br>subplot(3,1,2);<br>plot(t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;dy/dt(t)&#39;);<br>title(&#39;Solution dy/dt(t) vs Time&#39;);<br>grid on;<br><br>subplot(3,1,3);<br>plot(t, Y(:,3), &#39;-.&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;d^2y/dt^2(t)&#39;);<br>title(&#39;Solution d^2y/dt^2(t) vs Time&#39;);<br>grid on;</pre><p>The full code is</p><pre>%%matlab<br><br>% Define the system of first-order DEs<br>dydt = @(t, Y) [Y(2); Y(3); 3*Y(3) - 3*Y(2) + Y(1) + cos(t)];<br><br>% Initial conditions and time span<br>Y0 = [1; 0; 0];      % y(0) = 1, dy/dt(0) = 0, d^2y/dt^2(0) = 0<br>tspan = [0 10];      % Time interval from t = 0 to t = 10<br><br>% Solve the DE using ode45<br>[t, Y] = ode45(dydt, tspan, Y0);<br><br>% Option 1: Plot all solutions on the same graph<br>figure;<br>plot(t, Y(:,1), &#39;-o&#39;, t, Y(:,2), &#39;-x&#39;, t, Y(:,3), &#39;-.&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;Solutions&#39;);<br>title(&#39;Solutions of the Third-Order DE&#39;);<br>legend(&#39;y(t)&#39;, &#39;dy/dt(t)&#39;, &#39;d^2y/dt^2(t)&#39;);<br>grid on;<br><br>% Option 2: Plot solutions on separate subplots<br>figure;<br>subplot(3,1,1);<br>plot(t, Y(:,1), &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;y(t)&#39;);<br>title(&#39;Solution y(t) vs Time&#39;);<br>grid on;<br><br>subplot(3,1,2);<br>plot(t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;dy/dt(t)&#39;);<br>title(&#39;Solution dy/dt(t) vs Time&#39;);<br>grid on;<br><br>subplot(3,1,3);<br>plot(t, Y(:,3), &#39;-.&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;d^2y/dt^2(t)&#39;);<br>title(&#39;Solution d^2y/dt^2(t) vs Time&#39;);<br>grid on;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*aem3MkqAXWcYIiBa8QIGEg@2x.jpeg" /></figure><h4>FOURTH ORDER DIFFERENTIAL EQUATIONS</h4><p>Let’s say we’re to solve with Matlab the differential equation;</p><p>d⁴y/dt⁴ + 2 d³y/dt³ + 3 d²y/dt² + 4 dy/dt = cos(t) – 0.5 exp(t)</p><p>With initial conditions y(0) = 0, y’(0) = 1, y”(0) = -1, y”’(0) = 0</p><p>Step 1: Convert the fourth-order equation to systems of first-order DEs</p><p>Let y = y₁</p><p>dy/dt = y₂</p><p>d²y/dt² = y₃</p><p>d³y/dt³ = y₄</p><p>So</p><p>dy₁/dt = y₂ — – – (1)</p><p>dy₂/dt = y₃ — – – (2)</p><p>dy₃/dt = y₄. — – – (3)</p><p>dy₄/dt = cos(t) – 0.5exp(t) – 2y₄ – 3y₃ – 4y₂ —(4)</p><p>Step 2: Define the system of DEs in Matlab</p><p>Step 3: Set the initial conditions and desirable timespan</p><p>Step 4: Solve the Systems using the ode solver</p><p>Step 5: Plot the solutions</p><p>The full code is</p><pre>% Define the system of first-order DEs<br>dydt = @(t, Y) [Y(2); Y(3); Y(4); cos(t) - 0.5*exp(t) - 2*Y(4) - 3*Y(3) - 4*Y(2) - Y(1)];<br><br>% Initial conditions and time span<br>Y0 = [0; 1; -1; 2]; % y(0) = 0, dy/dt(0) = 1, d^2y/dt^2(0) = -1, d^3y/dt^3(0) = 2<br>tspan = [0 10];<br><br>% Solve using ode45<br>[t, Y] = ode45(dydt, tspan, Y0);<br><br>% Create a figure with 4 subplots<br>figure;<br><br>% First subplot: y(t)<br>subplot(4, 1, 1);<br>plot(t, Y(:,1), &#39;-o&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;y(t)&#39;);<br>title(&#39;y(t) vs Time&#39;);<br>grid on;<br><br>% Second subplot: dy/dt(t)<br>subplot(4, 1, 2);<br>plot(t, Y(:,2), &#39;-x&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;dy/dt(t)&#39;);<br>title(&#39;dy/dt(t) vs Time&#39;);<br>grid on;<br><br>% Third subplot: d^2y/dt^2(t)<br>subplot(4, 1, 3);<br>plot(t, Y(:,3), &#39;-.&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;d^2y/dt^2(t)&#39;);<br>title(&#39;d^2y/dt^2(t) vs Time&#39;);<br>grid on;<br><br>% Fourth subplot: d^3y/dt^3(t)<br>subplot(4, 1, 4);<br>plot(t, Y(:,4), &#39;--&#39;);<br>xlabel(&#39;Time t&#39;);<br>ylabel(&#39;d^3y/dt^3(t)&#39;);<br>title(&#39;d^3y/dt^3(t) vs Time&#39;);<br>grid on;<br><br>% Improve spacing between subplots<br>sgtitle(&#39;Solution of Fourth-Order DE&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*Hd2VYyYOum1ZTTMAv2fLHQ@2x.jpeg" /></figure><h3>SUMMARY</h3><p>First Order DEs can be solved directly</p><p>Higher-order DEs need to be first converted into systems of first-order DEs before solving.</p><p>Ode45 function is very powerful and handles most of the non-stiff differential equations well.</p><p>Plotting of functions in Matlab helps us to visualize and analyze each component of the solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5444e682124" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ROOT FINDING TECHNIQUES IN MATLAB: Newton Raphson, Secant and Bisection methods]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/root-finding-techniques-in-matlab-newton-raphson-secant-and-bisection-methods-be7db7e39b1b?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/be7db7e39b1b</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[math]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Wed, 21 Aug 2024 18:51:21 GMT</pubDate>
            <atom:updated>2024-08-22T08:56:12.524Z</atom:updated>
            <content:encoded><![CDATA[<h3>Root-Finding Techniques in MATLAB: Newton Raphson, Secant and Bisection methods</h3><h4>A guide to Newton Raphson, Secant and Bisection methods</h4><p>In Computational worlds, finding the roots of non-linear equations is important. This article explores the Newton Raphson, Secant and Bisection Methods all implemented in MATLAB, offering practical insights into their algorithm and convergence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNclRwZqGYOV4dtN51Fkjg@2x.jpeg" /></figure><h3>Newton Raphson algorithm in MATLAB</h3><p>Suppose we’re to solve the same equation y = exp(x) – exp(-2x) + 1</p><h4>STEP 1: Define the function</h4><pre>f = @(x) exp(x) – exp(-2*x) + 1;</pre><p>This line define the function we’re finding the root of.</p><p>The @ syntax create an anonymous function I.e we can use it directly without defining the function in different file</p><h4>Step 2: Define the Derivative</h4><pre>f_prime = @(x) exp(x) + 2*exp(-2*x);</pre><p>The line define the derivative which is important in NR method. The derivative will be used in the iteration formula to obtain the guess solution</p><h4>Step 3: Initial gues</h4><pre>x0 = 1;</pre><p>The line starts with this initial value</p><h4>Step 4: Set the Tolerance and Maximum Iterations</h4><pre>tol = 1e-7;<br>max_iter = 15;</pre><p>tol is the tolerance level. The iteration will stop if the differences between the successive approximation is less than this which indicates that the solution has converge. max_iter is the maximum number of iteration allowed. It safe us from running the computation indefinitely if it doesn’t converges</p><h4>Step 5: Newton Iteration Set up</h4><pre>x = x0;<br>fprintf(&#39;Iteration\t x_n\t\t\t f(x_n)\t\t\t f&#39;&#39;(x_n)\t\t\t |x_{n+1} - x_n|\n&#39;);<br>fprintf(&#39;-----------\n&#39;);</pre><p>x= x0 set the current guess of x to initial guess x0. The first fprintf print the header for the iteration table by labeling the column as : iteration number, current guess, f(x_n), f’(x_n) and abs(x_{n+1} – x_n)</p><p>The second fprintf print space for easy</p><p>reading</p><h4>Step 6: Iteration loop</h4><pre>for i = 1:max_iter</pre><p>This loop run the iteration from the x0 to</p><p>the maximum iteration set. ( i ) is the iteration counter</p><h4>Step 7: Calculate the next approximation</h4><pre>x_new = x - f(x)/f_prime(x);</pre><p>This line applies NR formula to compute the new guess x_new. f_prime(x) is the derivative of f(x)</p><h4>Step 8: Display the current Iteration Results</h4><pre>fprintf(&#39;%d\t\t %.8f\t %.8f\t %.8f\t %.8f\n&#39;, i, x, f(x), f_prime(x), abs(x_new - x));</pre><p>This line print the result of the current iteration. It displays the iteration i, current guess x_n, the function of the guess f(x_n), the derivative of the function f’(x_n) %.8f format the number to 8 decimal place.</p><h4>Step 9: Test for convergence</h4><pre>if abs(x_new - x) &lt; tol<br>    break;<br>end</pre><p>This line checks if the difference between the current and previous guess is less than the set tolerance value. If this condition is met, the loop breaks indicating the convergence to the root</p><h4>Step 9: Update the new Guess</h4><pre>x = x_new;</pre><p>This line set the current guess for the next iteration</p><h4>Step 10: Display Final result</h4><pre>fprintf(&#39;\nThe root is approximately x = %.8f after %d iterations.\n&#39;, x, i);</pre><p>After this loop finishes, this line print the final approximation of the root and the total iteration i required.</p><h4>The Complete Code is this;</h4><pre>%%%% MATLAB<br><br>% Define the function<br>f = @(x) exp(x) - exp(-2*x) + 1;<br><br>% Define the derivative of the function<br>f_prime = @(x) exp(x) + 2*exp(-2*x);<br><br>% Initial guess<br>x0 = 1;<br><br>% Tolerance and maximum iterations<br>tol = 1e-7;<br>max_iter = 15;<br><br>% Newton-Raphson iteration<br>x = x0;<br>fprintf(&#39;Iteration\t x_n\t\t\t f(x_n)\t\t\t f&#39;&#39;(x_n)\t\t\t |x_{n+1} - x_n|\n&#39;);<br>fprintf(&#39;-------------\n&#39;);<br><br>for i = 1:max_iter<br>    % Calculate the next approximation<br>    x_new = x - f(x)/f_prime(x);<br>    <br>    % Display the current iteration, x_n, f(x_n), f&#39;(x_n), and the difference<br>    fprintf(&#39;%d\t\t %.8f\t %.8f\t %.8f\t %.8f\n&#39;, i, x, f(x), f_prime(x), abs(x_new - x));<br>    <br>    % Check if the difference is within the tolerance<br>    if abs(x_new - x) &lt; tol<br>        break;<br>    end<br>    <br>    x = x_new; % Update the current guess<br>end<br><br>% Display the final result<br>fprintf(&#39;\nThe root is approximately x = %.8f after %d iterations.\n&#39;, x, i);</pre><pre>%%% RESULT<br><br>Iteration	 x_n			 f(x_n)			 f&#39;(x_n)			 |x_{n+1} - x_n|<br>------------------------------------------------------<br>1		 0.0000000000	 1.0000000000	 3.0000000000	 0.3333333333<br>2		 -0.3333333333	 -0.2312027305	 4.6119993927	 0.0501306940<br>3		 -0.2832026393	 -0.0085549245	 4.2772111808	 0.0020001174<br>4		 -0.2812025219	 -0.0000125703	 4.2646514643	 0.0000029476<br>5		 -0.2811995743	 -0.0000000000	 4.2646329988	 0.0000000000<br><br>The root is approximately x = -0.2811995743 after 5 iterations.<br></pre><h3>BISECTION METHOD</h3><p>Suppose we are to solve the equation;</p><p>y = exp(x) – exp(-2x) + 1</p><h3>The following is how to run it on matlab easily ;</h3><h4>Step1: Define the function</h4><pre>   f = @(x) exp(x) - exp(-2*x) +1;</pre><p>This line define function we want to find the roots of. The @(x) synatax creates an anonymous function which is not stored in Matlab file</p><h4>Step 2: Set the initial Interval</h4><pre>  a = -1;<br>   b =  1;</pre><p>This line suspect the interval where we the roots will lie</p><p>For Bisection Algorithm, f(a) and f(b) must have an opposite sign. Simply put f(a)•f(b)&lt;0 have an opposite sign. Simply put f(a)•f(b)&lt;0</p><h4>Step 3: Set the tolerance and Iterations</h4><pre>tol = 1e^-5;<br>     max_iter = 15;</pre><p>This lines defines the stopping criteria</p><p>tol = 1e^-5 means how close the function f(c) need to be to close to zero or how small the interval [a ,b] should be before iteration stops</p><p>max_iter = 15 limits the number to 15 in other to prevent an infinite iterations other to prevent an infinite iterations</p><h4>Step 4: Check the criteria for convergence</h4><pre>   If f(a)*f(b)&gt;0<br>       error(’f(a) and f(b) must have an opposite sign’);<br>  end</pre><p>This line checks if f(a) and f(b) have same sign (either both positive or negative). If they do, the interval does not contain the roots and the method will not work</p><h4>Step 5: Bisection Iteration loops</h4><pre>for i = 1:max_iter</pre><p>This begin a loops that iterates from the beginning to the max_iter desired</p><h4>Step 6: Calculate the midpoint</h4><pre>   c = ( a + b)/2;</pre><p>The midpoint is where the method will evaluate the function to decide which half of the interval to keep for the successive iteration</p><h4>Step 7: Display the current iteration</h4><pre>fprintf(’ Iteration %d:  a = %.7f, b = %.7f, c = %.7f, f(c) = %.7f, |b-a| = %.7f \n’, …i, a, b, c, f(c), abs(b-a));</pre><p>This line print the details of the current iteration. The format %.7f ensures the numbers are in 7 decimal places. The fprintf is used to display the current iteration number i, the values of a,b,c f(c)</p><h4>Step 8: Check for convergence</h4><pre> If abs(f(c)) &lt; tol | | abs(b-a) &lt; tol<br>    break;<br> end</pre><p>This line checks whether the method has converge to a root</p><p>abs(f(c)) &lt; tol checks if the function at c is close enough to zero within the tolerance we’ve set</p><p>abs(b-a) &lt; tol checks if the interval set is becoming very small which tells that c is a good approximation of the root</p><p>If the either of the condition is met, the loop breaks and the iteration stops</p><h4>Step 9: Decide the next subinterval to set</h4><pre>If f(a)*f(c) &lt; 0;<br>     b = c % the roots lies between a and c<br> else<br>    a = c; % the roots lies between b and c<br>end</pre><p>This line determine the half of the current interval to keep</p><p>If f(a)*f(c) &lt; 0, the root lies between a &amp; c so the interval is updated by setting b = c</p><p>Otherwise, the root lies between c &amp; b, the interval is again updated by setting a = c</p><h4>Step 10: Display the results</h4><pre>fprintf(’\nThe root is approximately x = %.7f after %d iterations. \n’ c, i );</pre><p>This line print the final result after the loop finishes. “c” is the midpoint of the final interval the total number of iteration is “i” took to converge is also displayed. ittoconverge is also displayed.</p><h4>The full code is this</h4><pre>%%%% MATLAB<br><br>% Define the function<br>f = @(x) exp(x) - exp(-2*x) + 1;<br><br>% Define the initial interval [a, b]<br>a = -1;<br>b = 1;<br><br>% Tolerance and maximum iterations<br>tol = 1e-5;<br>max_iter = 15;<br><br>% Check if the initial interval is valid<br>if f(a) * f(b) &gt;= 0<br>    error(&#39;f(a) and f(b) must have opposite signs&#39;);<br>end<br><br>% Bisection Method iteration<br>for i = 1:max_iter<br><br>    % Calculate the midpoint<br>    c = (a + b)/2;<br>    <br>    % Display the current iteration<br>    fprintf(&#39;Iteration %d: a = %.7f, b = %.7f, c = %.7f, f(c) = %.7f, |b-a| = %.7f\n&#39;, ...<br>            i, a, b, c, f(c), abs(b - a));<br>    <br>    % Check if the root is found or if the interval is small enough<br>    if abs(f(c)) &lt; tol || abs(b - a) &lt; tol<br>        break;<br>    end<br>    <br>    % Decide which subinterval to use for the next step<br>    if f(a) * f(c) &lt; 0<br>        b = c;  % The root lies between a and c<br>    else<br>        a = c;  % The root lies between c and b<br>    end<br>end<br><br>% Display the final result<br>fprintf(&#39;\nThe root is approximately x = %.7f after %d iterations.\n&#39;, c, i);</pre><pre>%%% Results <br><br>Iteration 1: a = -1.0000000, b = 1.0000000, c = 0.0000000, f(c) = 1.0000000, |b-a| = 2.0000000<br>Iteration 2: a = -1.0000000, b = 0.0000000, c = -0.5000000, f(c) = -1.1117512, |b-a| = 1.0000000<br>Iteration 3: a = -0.5000000, b = 0.0000000, c = -0.2500000, f(c) = 0.1300795, |b-a| = 0.5000000<br>Iteration 4: a = -0.5000000, b = -0.2500000, c = -0.3750000, f(c) = -0.4297107, |b-a| = 0.2500000<br>Iteration 5: a = -0.3750000, b = -0.2500000, c = -0.3125000, f(c) = -0.1366303, |b-a| = 0.1250000<br>Iteration 6: a = -0.3125000, b = -0.2500000, c = -0.2812500, f(c) = -0.0002151, |b-a| = 0.0625000<br>Iteration 7: a = -0.2812500, b = -0.2500000, c = -0.2656250, f(c) = 0.0656693, |b-a| = 0.0312500<br>Iteration 8: a = -0.2812500, b = -0.2656250, c = -0.2734375, f(c) = 0.0329148, |b-a| = 0.0156250<br>Iteration 9: a = -0.2812500, b = -0.2734375, c = -0.2773438, f(c) = 0.0163972, |b-a| = 0.0078125<br>Iteration 10: a = -0.2812500, b = -0.2773438, c = -0.2792969, f(c) = 0.0081030, |b-a| = 0.0039062<br>Iteration 11: a = -0.2812500, b = -0.2792969, c = -0.2802734, f(c) = 0.0039469, |b-a| = 0.0019531<br>Iteration 12: a = -0.2812500, b = -0.2802734, c = -0.2807617, f(c) = 0.0018667, |b-a| = 0.0009766<br>Iteration 13: a = -0.2812500, b = -0.2807617, c = -0.2810059, f(c) = 0.0008260, |b-a| = 0.0004883<br>Iteration 14: a = -0.2812500, b = -0.2810059, c = -0.2811279, f(c) = 0.0003055, |b-a| = 0.0002441<br>Iteration 15: a = -0.2812500, b = -0.2811279, c = -0.2811890, f(c) = 0.0000452, |b-a| = 0.0001221<br><br>The root is approximately x = -0.2811890 after 15 iterations.</pre><h3>SECANT METHOD</h3><h3>Secant Algorithm in MATLAB</h3><p>Suppose we are to solve;</p><p>y = exp(x) – exp(-2x) + 1</p><h4>Step 1: Define the function</h4><pre>f = @(x) exp(x) - exp(-2*x) + 1;</pre><h4>Step 2: set the initial guess</h4><pre>x0 = -1;<br>x1 = 1;</pre><p>x0 and x1 are the initial guesses for the root. These are the starting points of the iteration</p><h4>Step 3: Set Tolerance and Maximum iteration</h4><pre>tol = 1e-6;<br>max_iter = 100;</pre><p>“tol” is the tolerance level. of the difference between successive approximations. The iteration stops when the difference between successive iteration is less than the tolerance. “max_iter” is the maximum number of iteration</p><h4>Step 4: Iteration loop</h4><pre>for i = 1:max_iter</pre><p>The loop continues iterating up to max_iter</p><h4>Step 5: Calculate the next iteration</h4><pre>x2 = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0));</pre><p>The line use the Secant formula to calculate the next approximation. Here x2 is the new guess</p><h4>Step 6: Display the current iteration</h4><pre>fprintf(&#39;Iteration %d: x0 = %.6f, x1 = %.6f, x2 = %.6f, f(x2) = %.6f\n&#39;, i, x0, x1, x2, f(x2));</pre><p>This line prints the current iteration value; the values are x0, x1, x2 and f(x2)</p><h4>Step 7: Test for convergence</h4><pre>if abs(x2 - x1) &lt; tol<br>    break;<br>end</pre><p>This checks whether the difference between the current approximation x2 and the previous x1 is less than tol. If it does, the loop breaks indicating the convergence</p><h4>Step 8: Update the variables</h4><pre>x0 = x1;<br>x1 = x2;</pre><p>This update the variables for next iteration</p><h4>Step 9: Display Final results</h4><pre>fprintf(&#39;\nThe root is approximately x = %.6f after %d iterations.\n&#39;, x2, i);<br> </pre><p>After the loop finishes, this line print the final approximation of the root and the number of iteration i it performs to converge</p><h4>The complete code is</h4><pre>%%% MATLAB<br><br>% Define the function<br>f = @(x) exp(x) - exp(-2*x) + 1;<br><br>% Initial guesses<br>x0 = -1;<br>x1 = 1;<br><br>% Tolerance and maximum iterations<br>tol = 1e-6;<br>max_iter = 100;<br><br>% Secant Method iteration<br>for i = 1:max_iter<br>    % Calculate the next approximation<br>    x2 = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0));<br>    <br>    % Display the current iteration<br>    fprintf(&#39;Iteration %d: x0 = %.6f, x1 = %.6f, x2 = %.6f, f(x2) = %.6f\n&#39;, ...<br>            i, x0, x1, x2, f(x2));<br>    <br>    % Check for convergence<br>    if abs(x2 - x1) &lt; tol<br>        break;<br>    end<br>    <br>    % Update variables<br>    x0 = x1;<br>    x1 = x2;<br>end<br><br>% Display the final result<br>fprintf(&#39;\nThe root is approximately x = %.6f after %d iterations.\n&#39;, x2, i);</pre><pre>%%% RESULT<br><br>Iteration 1: x0 = -1.000000, x1 = 1.000000, x2 = 0.253873, f(x2) = 1.687158<br>Iteration 2: x0 = 1.000000, x1 = 0.253873, x2 = -0.410143, f(x2) = -0.607592<br>Iteration 3: x0 = 0.253873, x1 = -0.410143, x2 = -0.234328, f(x2) = 0.193257<br>Iteration 4: x0 = -0.410143, x1 = -0.234328, x2 = -0.276755, f(x2) = 0.018894<br>Iteration 5: x0 = -0.234328, x1 = -0.276755, x2 = -0.281352, f(x2) = -0.000650<br>Iteration 6: x0 = -0.276755, x1 = -0.281352, x2 = -0.281199, f(x2) = 0.000002<br>Iteration 7: x0 = -0.281352, x1 = -0.281199, x2 = -0.281200, f(x2) = 0.000000<br><br>The root is approximately x = -0.281200 after 7 iterations.<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be7db7e39b1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Active Noise Cancellation in AirPods Using Partial Differential Equations]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/analyzing-active-noise-cancellation-in-airpods-using-partial-differential-equations-3ef4dfa26965?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef4dfa26965</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 06:45:01 GMT</pubDate>
            <atom:updated>2024-08-18T06:54:07.248Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*LxQX_5zjZDUOjGq161gtPw@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*z6htyCj8misRSclmR-Nyvg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*j5u0mHyv2edHQEUKjXxOAg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*nXvLpwT1RQXWzZqytmGxog@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*IrSWPeKnCtuQA_OZExAUFA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*goxYM3aUZLYxSd9AWqRqpA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*3hzfUkK2SwVltUGD60hj-Q@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*5ehX1SJbUKoxYUJJozwplg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*atu-usHqyFdXsoMtno3UTA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ek4Rso9bNhkAuVyPlHoH4A@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*1BO7R6Or7B4uHnP4mQtLsg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*Ta3MZCN-oSArCoWMQP7N-w@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef4dfa26965" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Noise Cancellation Systems Using SIMULINK]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/noise-cancellation-systems-using-simulink-014fd7236b7d?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/014fd7236b7d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Sat, 17 Aug 2024 18:00:16 GMT</pubDate>
            <atom:updated>2024-08-17T18:07:32.001Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction to Active Noise Control (ANC)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*aYr2_C2fbw0BPcZvr0cSAg@2x.jpeg" /></figure><p>Active Noise Control (ANC) is a sophisticated technique designed to reduce unwanted sound by generating an “anti-noise” signal that effectively cancels out the undesired sound waves. This method has found widespread application across various fields, including noise-canceling headphones, automotive sound management, and noise reduction in ventilation systems. The fundamental principle behind ANC is destructive interference, where the anti-noise signal is phase-inverted to neutralize the noise.</p><p>This article delves into the implementation of ANC using Simulink Real-Time, a powerful platform that facilitates real-time prototyping and testing of control systems. We will focus on the model-based design of ANC and its subsequent execution on real-time hardware, providing a comprehensive guide for engineers and researchers working in this field.</p><h3>ANC System Design and Model-Based Approach</h3><p>Designing an ANC system involves a series of stages that begin with model-based simulation and eventually lead to real-time implementation. Initially, the ANC system is modeled and simulated using a simple acoustic model in Simulink, without the need for physical hardware. This allows for rigorous testing and refinement within a controlled environment.</p><p>Once the model is validated, the next step is real-time implementation. This is achieved by utilizing Speedgoat Target Computers and support modules, which serve as external real-time targets for Simulink. This setup enables the execution of the model in real-time, allowing for continuous monitoring of crucial system parameters such as adaptive filter coefficients.</p><p>A pivotal aspect of ANC design is the feedback loop. In this system, a reference microphone captures the noise source, and an error microphone measures the residual noise after the cancellation process. The adaptive ANC filter then adjusts based on the error signal to minimize it, effectively reducing the overall noise level.</p><p>ANC Feedforward Model</p><p>The feedforward ANC system is a classic approach to noise cancellation. In this system, the noise source (such as a fan) is detected by a reference microphone positioned at the entrance of a duct. The system then generates an anti-noise signal through a loudspeaker, effectively canceling out the detected noise.</p><h3>Key components of the feedforward ANC model include:</h3><h4>Reference Microphone</h4><blockquote>Function:</blockquote><blockquote>Captures the primary noise signal (the unwanted noise) that the system aims to cancel. This signal serves as the input to the adaptive filter.</blockquote><h4>2. Adaptive Filter (W(z))</h4><blockquote>Function:</blockquote><blockquote>The adaptive filter generates the anti-noise signal based on the reference microphone’s input. The filter’s coefficients are dynamically adjusted by the LMS algorithm to minimize the error signal. The design of the filter considers both the primary noise and the effect of the secondary path (discussed below).</blockquote><h4>3. Primary Path (P(z))</h4><blockquote>Function:</blockquote><blockquote>This block models the transfer function from the noise source to the error microphone, representing the direct path that the noise takes in the environment. The model of this path helps in understanding how the noise propagates, which is essential for effective cancellation.</blockquote><h4>4. Secondary Path (S(z))</h4><blockquote>Function:</blockquote><blockquote>Represents the transfer function from the ANC output (the anti-noise signal) to the error microphone. This path includes any delays or distortions that the anti-noise signal might experience before it combines with the actual noise. The Filtered-X LMS algorithm accounts for this secondary path to enhance the accuracy of noise cancellation.</blockquote><h4>5. Filtered-X Block</h4><blockquote>Function:</blockquote><blockquote>This block is crucial in the FXLMS algorithm. It filters the reference signal through the estimated secondary path model, simulating how the anti-noise signal will interact with the environment. This filtered signal is used to update the adaptive filter’s coefficients. By doing this, the algorithm compensates for the distortions introduced by the secondary path, improving the effectiveness of the noise cancellation.</blockquote><h4>6. Error Microphone</h4><blockquote>Function:</blockquote><blockquote>Captures the residual noise after the anti-noise signal has been applied. This residual noise is the difference between the actual noise and the generated anti-noise. The error signal is used by the LMS algorithm to adjust the adaptive filter, aiming to minimize the residual noise.</blockquote><h4>7. LMS Update Block</h4><blockquote>Function:</blockquote><blockquote>Implements the Least Mean Squares (LMS) algorithm, specifically its Filtered-X variant. It updates the adaptive filter’s coefficients based on the error signal and the filtered reference signal. The goal of this block is to continuously minimize the error signal, ensuring that the anti-noise signal effectively cancels out the primary noise.</blockquote><h4>8. Anti-Noise Generator</h4><blockquote>Function:</blockquote><blockquote>Converts the output of the adaptive filter into a physical anti-noise signal that is played back into the environment through a loudspeaker. This signal is designed to destructively interfere with the unwanted noise, reducing or eliminating it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*7GB0XO8vnOu0GneJT-M48w@2x.jpeg" /></figure><h4>Filtered-X ANC Model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*y27MrAWVunkGmsc9AAbIKg@2x.jpeg" /></figure><p>The Filtered-X Least Mean Squares (FXLMS) algorithm is an enhanced version of the standard LMS algorithm, specifically designed for ANC systems. This model considers both the primary and secondary paths, making it more resilient to variations in the acoustic environment.</p><p>The implementation of the Filtered-X ANC model follows these steps:</p><ol><li>Simulation of the Environment:</li></ol><blockquote>Begin with a basic model of the ANC system and the acoustic environment, including the duct through which noise propagates.</blockquote><p>2. Estimation of the Secondary Path:</p><blockquote>Accurately estimate the secondary path, which influences how the anti-noise signal interacts with the environment. This step is crucial for precise noise cancellation.</blockquote><p>3. LMS Update Block:</p><blockquote>Configure the LMS update block to minimize the error signal, which is a combination of the noise source filtered by both the primary and secondary paths.</blockquote><p>This model allows for iterative refinement as more information is gathered about the real-world system. For instance, acoustic feedback or measurement noise can be introduced into the simulation to replicate real-world conditions, helping to enhance the robustness of the ANC system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*y27MrAWVunkGmsc9AAbIKg@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*gtfN43mN94-bF2vprZSXcQ@2x.jpeg" /></figure><h4>Secondary Path Estimation Model</h4><p>In ANC systems, accurately estimating the secondary path is vital. The secondary path is the route that the anti-noise signal follows from the ANC loudspeaker to the error microphone. Key considerations include:</p><p>Adaptive Filter:</p><blockquote>An adaptive filter is utilized to identify the unknown system. This filter dynamically adjusts its parameters to minimize the error between the desired and actual outputs.</blockquote><p>Convergence:</p><blockquote>The goal is for the adaptive filter to converge to a specific function, ensuring precise modeling of the secondary path.</blockquote><p>Latency Considerations:</p><blockquote>Minimizing latency is critical in real-time systems to ensure effective ANC. Speedgoat hardware is employed to achieve the low latency necessary for successful ANC implementation.</blockquote><p>Implementation Details:</p><blockquote>The ANC system is implemented in real-time using Simulink and Speedgoat, with steps including replacing acoustic models with Speedgoat I/O blocks and incorporating logic to measure the secondary path before transitioning to the actual ANC mode.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*RbusEyDnjFfC6tF4E2NVtw@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*XyMHVsEtjC9x_1PpltQpNw@2x.jpeg" /></figure><h4>Conclusion</h4><p>Implementing ANC systems using Simulink Real-Time offers a robust platform for both simulation and real-time prototyping. The model-based approach provides extensive testing and refinement capabilities before deployment on real hardware, making it ideal for applications where effective noise reduction is essential. The combination of feedforward and filtered-X ANC models illustrates the flexibility and adaptability needed to achieve optimal noise cancellation in diverse environments.</p><p>By following the steps outlined in this article, engineers and researchers can leverage Simulink Real-Time to design, simulate, and implement efficient ANC systems, contributing to advancements in noise control technologies across various industries.</p><p>(C) Mathworks inc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=014fd7236b7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating MATLAB with ChatGPT]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/integrating-matlab-with-chatgpt-dd62a6d91116?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd62a6d91116</guid>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 23:39:01 GMT</pubDate>
            <atom:updated>2024-08-05T23:39:01.524Z</atom:updated>
            <content:encoded><![CDATA[<h3>Revolutionizing Scientific and Engineering Workflows.</h3><p>Imagine having an AI coding assistant that streamlines science and engineering work, generates sufficient codes, and optimizes algorithms on demand.</p><p>This vision is now a reality with the integration of MATLAB and OpenAI’s ChatGPT. By leveraging the power of ChatGPT within MATLAB, engineers and scientists can enhance their workflows, automate repetitive tasks, and focus on creative problem-solving. This article provides a comprehensive guide on how to achieve this integration, including practical examples and step-by-step instructions.</p><h4>Introduction to ChatGPT and MATLAB</h4><p>ChatGPT, developed by OpenAI, is a state-of-the-art language model capable of understanding and generating human-like text based on the input it receives. This AI tool can assist with coding, debugging, and even explaining complex concepts. MATLAB, on the other hand, is a high-level programming environment widely used for numerical computation, visualization, and algorithm development. By integrating ChatGPT with MATLAB, users can unlock new levels of productivity and innovation.</p><h4>Benefits of Integrating ChatGPT with MATLAB</h4><blockquote>Automating Code Generation</blockquote><p>One of the most significant benefits of integrating ChatGPT with MATLAB is the ability to automate code generation. Users can describe the functionality they need in natural language, and ChatGPT can provide the corresponding MATLAB code. This feature is especially useful for repetitive tasks or when working on unfamiliar problems.</p><blockquote>2. Enhancing Debugging and Troubleshooting</blockquote><p>Debugging can be a time-consuming and frustrating process. With ChatGPT, users can get immediate assistance in understanding error messages and identifying potential fixes. By describing the issue in plain language, ChatGPT can offer suggestions and solutions, reducing the time spent on debugging.</p><blockquote>3. Optimizing Algorithms</blockquote><p>Optimization is crucial in scientific and engineering computations. ChatGPT can help identify inefficiencies in existing code and suggest optimized algorithms. This capability ensures that users can achieve better performance and more accurate results in their computations.</p><h4>Step-by-Step Guide to Integrating ChatGPT with MATLAB</h4><blockquote>Step 1: Obtain an OpenAI API Key</blockquote><p>To integrate ChatGPT with MATLAB, you need an API key from OpenAI. Sign up on the OpenAI website, subscribe to a suitable plan, and generate your API key. Keep this key secure, as it is required for authentication in your requests to the OpenAI API.</p><blockquote>Step 2: Setting Up MATLAB for Web Requests</blockquote><p>MATLAB provides built-in functions like webread, webwrite, and weboptions to interact with web services. These functions will be used to communicate with the OpenAI API.</p><blockquote>Step 3: Writing the MATLAB Script</blockquote><p>Here’s an example script to make a request to the OpenAI API from MATLAB:</p><p>% Define the API endpoint and your API key</p><p>apiKey = ‘YOUR_OPENAI_API_KEY’;</p><p>apiUrl = ‘https://api.openai.com/v1/completions’;</p><p>% Create the request payload</p><p>data = struct();</p><p>data.model = ‘text-davinci-003&#39;;</p><p>data.prompt = ‘Explain the result of a 4x4 magic square in MATLAB.’;</p><p>data.max_tokens = 100;</p><p>% Convert the data to JSON format</p><p>jsonData = jsonencode(data);</p><p>% Set up the web options with the appropriate headers</p><p>options = weboptions(‘HeaderFields’, {</p><p>. ‘Content-Type’ ‘application/json’;</p><p>. ‘Authorization’ [‘Bearer ‘ apiKey]</p><p>}, ‘RequestMethod’, ‘post’, ‘MediaType’, ‘application/json’);</p><p>% Send the POST request</p><p>response = webwrite(apiUrl, jsonData, options);</p><p>% Decode the JSON response</p><p>responseData = jsondecode(response);</p><p>% Display the response</p><p>disp(responseData.choices{1}.text);</p><blockquote>Step 4: Customizing the Prompt</blockquote><p>To tailor the responses to your specific needs, customize the data.prompt field. For example, if you have a result from a MATLAB function and want an explanation:</p><p>result = magic(4);</p><p>prompt = sprintf(‘The result of the 4x4 magic square is: %s. Can you explain it?’, mat2str(result));</p><p>data.prompt = prompt;</p><p>This customization ensures that ChatGPT provides contextually relevant responses based on your MATLAB computations.</p><h4>Practical Applications</h4><blockquote>Generating MATLAB Code for Specific Tasks</blockquote><blockquote>Imagine you need to create a script for solving a partial differential equation (PDE). Instead of writing the code from scratch, you can describe the problem to ChatGPT and receive a ready-to-use MATLAB script. This feature significantly speeds up the coding process and ensures accuracy.</blockquote><blockquote>2. Explaining Complex Results</blockquote><p>In scientific research, interpreting complex results can be challenging. By integrating ChatGPT, you can get detailed explanations of your results in plain language, making it easier to understand and communicate findings to others.</p><blockquote>3. Learning and Education</blockquote><p>For students and educators, ChatGPT integrated with MATLAB serves as a valuable learning tool. It can provide code examples, explain concepts, and offer guidance on MATLAB programming, enhancing the educational experience.</p><h3>Conclusion</h3><p>The integration of MATLAB with ChatGPT opens up new possibilities for enhancing productivity, automating tasks, and optimizing algorithms in scientific and engineering workflows. By following the steps outlined in this article, you can leverage the power of AI to transform the way you work with MATLAB. Whether you’re generating code, debugging, or seeking explanations for complex results, ChatGPT provides a versatile and powerful assistant to help you achieve your goals.</p><blockquote>Watch how to go about the MATGPT setup here from MathWorks</blockquote><blockquote>https://youtu.be/gEOOEp3Kmko?si=uroSLB95EB2HGEOh</blockquote><p>(c) Abdulrasheed Kamal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*rVs5NaOzYEIsn8YngHsG_g@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd62a6d91116" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A solution to two sets of Integrals involving Inverse Tangent function]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/a-solution-to-two-sets-of-integrals-involving-inverse-tangent-function-a5d65eb3551b?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d65eb3551b</guid>
            <category><![CDATA[science]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[writing]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Mon, 05 Aug 2024 15:19:16 GMT</pubDate>
            <atom:updated>2024-08-05T15:19:16.222Z</atom:updated>
            <content:encoded><![CDATA[<p>Problem;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*f1-CRrSG-o7TyJTEInb0og@2x.jpeg" /></figure><h3>My Solutions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*SG1-x1C9qtZ43PD_ovLG1A@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*f9HvuXi52O4ybFqXGlKCSw@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*VjaUD2kX-QF4X3KvzMSH8Q@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ObkdsbIEQIY6bF5mptpy_w@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ML5I-pL4E0bJxavW56NXEQ@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d65eb3551b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing Menstrual Cycle Using Fourier Series.]]></title>
            <link>https://medium.com/@abdulrasheedkamal40/mathematics-of-menstrual-cycle-c7be83c34ef3?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7be83c34ef3</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 09:18:39 GMT</pubDate>
            <atom:updated>2024-07-25T14:52:40.280Z</atom:updated>
            <content:encoded><![CDATA[<h3>Methodology: Fourier Series</h3><p>The menstrual cycle is a complex biological process regulated by hormonal changes in the female body. Mathematically modeling this cycle can provide in- sights into its dynamics and help in various medical and scientific applications.</p><p>This article explores the mathematical representation of the menstrual cycle, focusing on a specific problem that uses the Fourier series to model the periodic flow profile.</p><p>Understanding the Menstrual Cycle</p><p>The menstrual cycle typically spans 28 days and can be divided into several phases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*6HFyxtvTIwyeZyC_E2u82A@2x.jpeg" /></figure><ol><li>Menstrual Phase (Days 1–5): The shedding of the uterine lining, re- sulting in menstrual flow.</li></ol><p>2. Follicular Phase (Days 1–13): The pituitary gland releases follicle- stimulating hormone (FSH), which stimulates the growth of ovarian folli- cles.</p><p>3. Ovulation (Day 14): The release of a mature egg from the ovary, trig- gered by a surge in luteinizing hormone (LH).</p><p>4. Luteal Phase (Days 15–28): The corpus luteum forms and secretes progesterone, preparing the uterus for a potential pregnancy.</p><p>Mathematical Model of Menstrual Flow</p><p>To model the menstrual flow mathematically, we consider a simplified version of the flow pattern. The flow builds up linearly to a peak, decreases linearly, and then remains at zero for the rest of the cycle. This periodic behavior can be effectively represented using a Fourier series.</p><p>Given the problem of modeling the menstrual flow Q(t) over a 28-day cycle, where the flow builds up linearly from 0 to q in the first two days, decreases linearly back to 0 in the next two days, and remains at 0 for the remaining 24 days,</p><p>we aim to:</p><ol><li>Obtain the mathematical expression for Q(t).</li></ol><p>2. Derive the Fourier series representation of Q(t).</p><p>3. Deduce specific sums involving trigonometric functions.</p><p>a) Mathematical Expression and Sketch of the Menstrual Flow Profile Q(t)</p><p>Flow Profile Definition</p><p>To derive the piecewise function Q(t) for the menstrual flow profile, we need to follow the given description of how the flow changes over time.</p><p>The problem states that the flow builds up linearly from 0 to q in the first two days, decreases linearly back to 0 in the next two days, and then remains at zero for the remaining 24 days of the cycle.</p><p>Here’s a step-by-step explanation of how we obtain the piecewise function:</p><p>. Step-by-Step Derivation of Q(t)</p><ol><li>Flow Build-Up (Days 0 to 2): From day 0 to day 2, the flow increases linearly from 0 to q. A linear function can model this.</li></ol><ul><li>At t = 0, Q(0) = 0.</li><li>• At t = 2, Q(2) = 9.</li></ul><p>The slope of the line is given by the change in flow divided by the change in time:</p><p>slope = q-0/(2–0) = q/2</p><p>Therefore, the equation of the line from t = 0 to t = 2 is:</p><p>Q(t) = q/2 ×t for 0&lt;t&lt;2</p><p>Flow Decrease (Days 2 to 4): From day 2 to day 4, the flow decreases linearly from q back to 0. This can also be modeled by a linear function.</p><ul><li>At t=2, Q(2) = q.</li><li>• At t =4, Q(4) = 0</li></ul><p>The attached image below contains a more detailed methodology of the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*RasWCM9lXFJtmC4C0VuhlQ@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*9uFCcuTbAEUmY2CgrOBvXA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*oZ7-gFPOcu_FRrVsTFmgaA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*uGxrAaaVasfJCNOT-C79fw@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*vWg_V6Lm8KTWt36eiDiDzQ@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*qkDwPfaZ3dCCJ3Hv9sYzQA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*m2j5uYHci9O-n4sZZQq0Ag@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*wyqhAs0oGXSegJI8vtUZcA@2x.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*86p14GzAJwmAtpEJrqQYzw@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7be83c34ef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Plotting Nyquist Diagrams and Applications in MATLAB for Aerospace Engineers]]></title>
            <link>https://thequantasticjournal.com/plotting-nyquist-diagrams-and-applications-in-matlab-for-aerospace-engineers-dd0e0644b610?source=rss-8353b82fd1f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd0e0644b610</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[space]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Abdulrasheed Kamal]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 08:48:56 GMT</pubDate>
            <atom:updated>2024-07-24T04:01:05.740Z</atom:updated>
            <content:encoded><![CDATA[<p>Nyquist diagrams are an essential tool in aerospace engineering for analyzing the stability of feedback systems. This article provides a detailed guide on plotting Nyquist diagrams using MATLAB, discussing their theoretical background and practical applications in the aerospace industry. Aerospace engineers will learn how to generate Nyquist plots, interpret them, and apply them to real-world engineering problems.</p><p>Nyquist diagrams are graphical representations used to determine the stability of control systems. They plot the frequency response of a system, particularly focusing on the phase and gain of the system as a function of frequency. This visual tool helps aerospace engineers assess whether a feedback control system is stable and predict its behavior.</p><p>MATLAB offers robust functions for generating Nyquist plots, making it a valuable tool for engineers in the design and analysis of aerospace control systems. This article will guide you through the process of plotting Nyquist diagrams in MATLAB and demonstrate their practical applications in aerospace engineering.</p><h3>Theoretical Background</h3><p>Nyquist diagrams plot the complex function. <em>G</em>(<em>j,ω</em>) over a range of frequencies <em>ω</em>, where. G(s) is the open-loop transfer function of the system, and <em>s = jω</em>.</p><p>The plot maps the frequency response of <em>G</em>(<em>j,ω</em>) on the complex plane, showing how the magnitude and phase vary with frequency.</p><p><em>Key Concepts:</em></p><blockquote>Gain and Phase Margins: These margins help determine the system’s stability. The gain margin is the factor by which the gain can be increased before the system becomes unstable, and the phase margin is the additional phase lag required to bring the system to the verge of instability.</blockquote><p><em>Nyquist Criterion:</em></p><blockquote>This criterion states that for a system to be stable, the Nyquist plot of the open-loop transfer function. G<em>(</em>j,ω<em>)</em> must encircle the critical point <em>(</em>–1 + 0 j <em>)</em> in the complex plane a specific number of times related to the number of poles in the right half-plane.</blockquote><h3>Plotting Nyquist Diagrams in MATLAB: Step-by-Step Implementation</h3><h4><strong><em>Define the Transfer Function</em></strong></h4><p>The first step is to define the transfer function of the system. MATLAB uses the tf function to represent transfer functions.</p><p>- <em>Define the numerator and denominator of the transfer function</em></p><pre>numerator = [1];<br>denominator = [1 3 3 1];</pre><p>- <em>Create the transfer function</em></p><pre>sys = tf(numerator, denominator);</pre><h4><strong><em>Plot the Nyquist Diagram</em></strong></h4><p>MATLAB provides the Nyquist function to plot the Nyquist diagram of a given transfer function.</p><p>- <em>Plot the Nyquist diagram</em></p><pre>nyquist(sys);<br>grid on;<br>title(&#39;Nyquist Diagram&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*_32kCENMXy2xXZsOkE7m3A@2x.jpeg" /></figure><h4><strong><em>Analyze the Plot</em></strong></h4><p>After generating the Nyquist plot, analyze it to determine the stability of the system. Check for encirclements of the critical point -1 + 0j and calculate the gain and phase margins.</p><h4><strong><em>Example</em></strong></h4><p>Here’s an example of plotting a Nyquist diagram for a given transfer function:</p><p>- Define the transfer function</p><pre>numerator = [2];<br>denominator = [1 2 2 1];<br>sys = tf(numerator, denominator);</pre><p>- Plot the Nyquist diagram</p><pre>nyquist(sys);<br>grid on;<br>title(&#39;Nyquist Diagram of the Transfer Function&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*GyK7GhUI8uLh-8kDXkTLjw@2x.jpeg" /><figcaption>Nyquist Diagram of the Transfer Function.</figcaption></figure><p>This code plots the Nyquist diagram for the transfer function:</p><p><em>G</em>(<em>s</em>) = <em>2/</em>(<em>s³ + 2s² + 2s + 1</em>)</p><h3>Practical Applications in Aerospace Engineering</h3><h4>Stability Analysis of Flight Control Systems</h4><p>Nyquist diagrams are crucial for analyzing the stability of flight control systems. Aerospace engineers use Nyquist plots to ensure that autopilot and flight control systems are stable under various operating conditions.</p><p><em>Example:</em></p><p>Suppose we need to analyze the stability of a pitch control system of an aircraft. We can use MATLAB to plot the Nyquist diagram and determine the stability margins.</p><p>- Define the pitch control system transfer function</p><pre>numerator = [1];<br>denominator = [1 3 3 1];<br>pitch_control_system = tf(numerator, denominator);</pre><p>- Plot the Nyquist diagram</p><pre>nyquist(pitch_control_system);<br>grid on;<br>title(&#39;Nyquist Diagram of Pitch Control System&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*6a21Xf24MIbjDV8YT6d0Mg@2x.jpeg" /><figcaption>Nyquist Diagram of Pitch Control System.</figcaption></figure><h4>Design and Tuning of Autopilot Systems</h4><p>Aerospace engineers use Nyquist plots to design and tune autopilot systems. By adjusting the parameters of the control system, they ensure the aircraft remains stable and responds correctly to pilot inputs and environmental disturbances.</p><p><em>Example:</em></p><p>To design a proportional-integral-derivative (PID) controller for an autopilot system, we can use the Nyquist plot to adjust the controller parameters.</p><p>- Define the aircraft transfer function</p><pre>numerator = [1];<br>denominator = [1 5 6];<br>aircraft = tf(numerator, denominator);</pre><p>- Define the PID controller</p><pre>Kp = 1; % Proportional gain<br>Ki = 1; % Integral gain<br>Kd = 0.5; % Derivative gain<br>controller = pid(Kp, Ki, Kd);</pre><p>- Combine the aircraft and controller</p><pre>sys = series(controller, aircraft);</pre><p>- Plot the Nyquist diagram of the closed-loop system</p><pre>nyquist(sys);<br>grid on;<br>title(&#39;Nyquist Diagram with PID Controller&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*guQ7YTyU2p_nV15HSJFOOw@2x.jpeg" /><figcaption>Nyquist Diagram with PID Controller.</figcaption></figure><p>By adjusting Kp , Ki , and Kd engineers can use the Nyquist plot to achieve the desired gain and phase margins, ensuring the system’s stability and performance.</p><h4>Stability of Aerospace Propulsion Systems</h4><p>Nyquist plots help ensure the stability of propulsion control systems, such as those in jet engines or rocket thrusters. These systems must remain stable under varying loads and operating conditions to maintain optimal performance and safety.</p><p><em>Example:</em></p><p>For a jet engine control system, engineers can plot the Nyquist diagram to analyze stability.</p><p>- Define the jet engine transfer function</p><pre>numerator = [1];<br>denominator = [1 4 6 4];<br>jet_engine = tf(numerator, denominator);</pre><p>- Plot the Nyquist diagram</p><pre>nyquist(jet_engine);<br>grid on;<br>title(&#39;Nyquist Diagram of Jet Engine Control System&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*m46Mnwc1Opom55VodPZqdQ@2x.jpeg" /><figcaption>Nyquist Diagram of Jet Engine Control System</figcaption></figure><h3>Finally,</h3><p>Nyquist diagrams are a powerful tool for aerospace engineers to analyze and design stable control systems. MATLAB’s built-in functions simplify the process of generating and interpreting these plots, making it an indispensable tool in aerospace engineering. By mastering Nyquist plots, aerospace engineers can ensure the stability and robustness of their control systems, leading to safer and more reliable aircraft and spacecraft designs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*anzspkv6vXATaR865B8PeA@2x.jpeg" /><figcaption>Nyquist Diagram of the Transfer Function.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd0e0644b610" width="1" height="1" alt=""><hr><p><a href="https://thequantasticjournal.com/plotting-nyquist-diagrams-and-applications-in-matlab-for-aerospace-engineers-dd0e0644b610">Plotting Nyquist Diagrams and Applications in MATLAB for Aerospace Engineers</a> was originally published in <a href="https://thequantasticjournal.com/">The Quantastic Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>