{"id":12719,"date":"2025-07-28T08:04:16","date_gmt":"2025-07-28T12:04:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/student-lounge\/?p=12719"},"modified":"2025-07-28T08:04:16","modified_gmt":"2025-07-28T12:04:16","slug":"how-satellites-use-game-theory-to-fly-in-perfect-formation-simulated-in-matlab","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/student-lounge\/2025\/07\/28\/how-satellites-use-game-theory-to-fly-in-perfect-formation-simulated-in-matlab\/","title":{"rendered":"How Satellites Use Game Theory to Fly in Perfect Formation \u2014 Simulated in MATLAB"},"content":{"rendered":"<div class=\"rtcContent\">\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"font-style: italic;\">Today\u2019s guest blogger is Maria Luisa, who\u2019s doing her PhD in Control Systems at Imperial College London and is also one of our MATLAB Student Ambassadors. Over to you, Maria..<\/span><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Introduction &amp; Motivation<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">What do poker players, self-driving cars, and satellites have in common? They all make strategic decisions under uncertainty. And believe it or not, they all rely on <span style=\"font-style: italic;\">game theory<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">In this blog, I\u2019ll walk you through how I used MATLAB to simulate a team of satellites flying in formation\u2014coordinating their actions like players in a cosmic chess game.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">I am Maria Luisa, a <a href=\"https:\/\/www.mathworks.com\/academia\/students\/student-ambassadors.html\">MATLAB Student Ambassador<\/a>, and I am currently doing a PhD in control systems at Imperial College London. I work in the field of differential game theory. More specifically, in this blog I will tackle the formation control problem of satellites using differential game theory.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Why Do Satellites Need to Play Games in Space?<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Formation flying is a growing concept in modern aerospace engineering. Whether it&#8217;s satellites working together to capture synchronized Earth imagery, measure climate variables, or deliver GPS signals, tight coordination is critical. But there\u2019s a challenge: space is unforgiving. Small errors in velocity or position can accumulate quickly, leading to significant drift over time.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">If one satellite corrects its trajectory, the others must respond appropriately to preserve the formation. And here\u2019s the interesting part\u2014each satellite is autonomous, acting based on its own goals and fuel constraints.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This scenario is a textbook example of a <span style=\"font-weight: bold;\">strategic decision-making problem under uncertainty<\/span>\u2014the domain of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Differential_game\"><span style=\"font-weight: bold;\">game theory<\/span><\/a>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Instead of central coordination, we model the satellites as <span style=\"font-weight: bold;\">players in a differential game<\/span>, each trying to optimize its own outcome (i.e., maintain formation while minimizing fuel usage), while accounting for the actions of the others. It&#8217;s not unlike poker: your best move depends on what the others are doing. The solution concept? A <a href=\"https:\/\/en.wikipedia.org\/wiki\/Nash_equilibrium#:~:text=A%20Nash%20equilibrium%20is%20a,of%20competition%20in%20an%20oligopoly.\"><span style=\"font-weight: bold;\">Nash equilibrium<\/span><\/a>\u2014a state where no satellite has an incentive to unilaterally change its strategy.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">In this project, we use <span style=\"font-weight: bold;\">MATLAB<\/span> to simulate this multi-agent coordination using tools from <a href=\"https:\/\/uk.mathworks.com\/discovery\/optimal-control.html\"><span style=\"font-weight: bold;\">optimal control<\/span><\/a> and <span style=\"font-weight: bold;\">game theory<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Modelling the Satellites<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Let\u2019s break down how we mathematically model this coordination problem.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">We consider a team of <span style=\"font-weight: bold;\">three satellites<\/span> in low Earth orbit. Each satellite has a thruster system it can use to slightly adjust its position and velocity. We model the dynamics using a <span style=\"font-weight: bold;\">linearized version of Newton\u2019s equations<\/span> around a reference orbit.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The system is described using a <span style=\"font-weight: bold;\">state-space model<\/span>:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 540px; height: 241px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/25July28_1.png\" alt=\"systemmatrix.png\" width=\"540\" height=\"241\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>In MATLAB, we construct this using <a href=\"https:\/\/uk.mathworks.com\/help\/matlab\/ref\/blkdiag.html\"><span style=\"font-family: monospace;\">blkdiag<\/span><\/a> for the overall <span style=\"font-family: STIXGeneral-webfont, serif; font-style: italic; font-weight: 400; color: #212121;\">A<\/span> matrix and control input matrices B1\u2009,B2\u2009,B3.<\/p>\n<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">What are they optimizing?<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Each satellite tries to:<\/div>\n<ol style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\"><span style=\"font-weight: bold;\">Stay close to the desired trajectory<\/span>,<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\"><span style=\"font-weight: bold;\">Use as little thrust as possible<\/span> (to save fuel).<\/li>\n<\/ol>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This leads us to define a <span style=\"font-weight: bold;\">cost functional<\/span> for each satellite. It penalizes both formation error and control effort:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 458px; height: 222px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/25July28_2.png\" alt=\"cost_functional.png\" width=\"458\" height=\"222\" \/><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">These matrices can be tuned in MATLAB to reflect different behaviors\u2014e.g., a satellite that prioritizes accuracy over fuel, or vice versa.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">Now that we\u2019ve modeled how each satellite moves and what it wants (stay in formation, save fuel), we need to remember that <span style=\"font-weight: bold;\">each satellite acts independently<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">That means Satellite 1 doesn&#8217;t know exactly what Satellite 2 or 3 will do\u2014it just assumes they\u2019ll act optimally. This situation is called a <span style=\"font-weight: bold;\">non-cooperative differential game<\/span>. That is, each player (satellite) is trying to minimize its own cost, while taking into account how the others will move.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This is where <span style=\"font-weight: bold;\">game theory<\/span> comes in. We\u2019re looking for a balance point where no satellite can improve its outcome by changing its strategy\u2014assuming the others keep theirs unchanged. That\u2019s called a <span style=\"font-weight: bold;\">Nash equilibrium<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Solving the differential game in MATLAB<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">To find the Nash equilibrium for our satellites, we need to solve a set of coupled <span style=\"font-weight: bold;\">Riccati-like matrix equations<\/span>. These arise from the <a href=\"https:\/\/repository.tilburguniversity.edu\/server\/api\/core\/bitstreams\/0abdb4ed-e84c-49f6-9f94-9c66154f6e11\/content\"><span style=\"font-weight: bold;\">Linear Quadratic Differential Game<\/span><\/a> formulation and they are a more complex version of the algebraic Riccati equation seen in standard LQR control. The equations for the three satellites are given by:<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"vertical-align: -6px;\">$ P_1A + A^\\top P_1 + Q_1 &#8211; P_1S_1P_1 &#8211; P_1S_2P_2 &#8211; P_1S_3P_3 &#8211; P_2S_2P_1 &#8211; P_3S_3P_1 = 0 $<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"vertical-align: -6px;\">$ P_2A + A^\\top P_2 + Q_2 &#8211; P_2S_2P_2 &#8211; P_2S_1P_1 &#8211; P_2S_3P_3 &#8211; P_1S_1P_2 &#8211; P_3S_3P_2 = 0 $<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><span style=\"vertical-align: -6px;\">$ P_3A + A^\\top P_3 + Q_3 &#8211; P-3S_3P_3 &#8211; P_3S_2P_2 &#8211; P_3S_1P_1 &#8211; P_2S_2P_3 &#8211; P_1S_1P_3 = 0 $<\/span><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>Where P1,P2,P3are the matrices we are solving for and<span style=\"vertical-align: -8px;\">$ S_i = B_iR_i^{-1}B_i^\\top $<\/span>. These equations are <span style=\"font-weight: bold;\">coupled<\/span> and <span style=\"font-weight: bold;\">nonlinear<\/span>, so we can\u2019t solve them directly in one step. Instead, we\u2019ll use MATLAB to solve them numerically. Here I will explain two methods we can use but other options can be available.<\/p>\n<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Method 1) Iterative Best-Response Dynamics<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The first approach is based on <span style=\"font-weight: bold;\">best-response iteration<\/span>, a fixed-point method where each player optimizes assuming the others are fixed. At each iteration, player <span style=\"font-family: STIXGeneral-webfont, serif; font-style: italic; font-weight: 400; color: #212121;\">i<\/span> solves a standard <a href=\"https:\/\/uk.mathworks.com\/help\/control\/ref\/icare.html\"><span style=\"font-family: monospace;\">iCARE<\/span><\/a> assuming current values of <span style=\"vertical-align: -6px;\">$ P_j, j \\neq i $<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<div style=\"font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #212121; line-height: 1.5;\">\n<p><strong>The idea of the algorithm can be summarized as:<\/strong><\/p>\n<ol style=\"padding-left: 20px; margin: 0;\">\n<li>Initialize \\(P_1\\), \\(P_2\\), and \\(P_3\\).<\/li>\n<li>For each \\(i \\in \\{1, 2, 3\\}\\), solve:<em>\\(P_i = \\mathrm{icare}\\bigl(A &#8211; \\sum_{j \\neq i} S_j P_j, B_i, Q_i, R_i\\bigr)\\)<\/em><\/li>\n<li>Repeat until convergence:<em>\\(\\|P_i^{(i)} &#8211; P_i^{(i-1)}\\| \\leq \\epsilon\\)<\/em><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This method is intuitive and efficient for problems where the interdependencies are smooth and well-behaved. Let\u2019s see some relevant parts of the code:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">%<\/span><span style=\"color: #008013;\"> Defining the initial guesses <\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P1_0 = P;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P2_0 = P;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P3_0 = P;<\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>We initialize each Pi with a common matrix P, often obtained from a centralized LQR solution or using icare. This gives us a feasible and symmetric starting point.<\/p>\n<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">while<\/span> norm(P1 &#8211; P1_0) &gt; tol &amp;&amp; <span style=\"color: #0e00ff;\">&#8230;<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> norm(P2 &#8211; P2_0) &gt; tol &amp;&amp; <span style=\"color: #0e00ff;\">&#8230;<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> norm(P3 &#8211; P3_0) &gt; tol<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Update K matrices using the iterative CARE solver<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P1 = icare(A &#8211; S2 * P2_0 &#8211; S3 * P3_0, B1, Q1, R1);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P2 = icare(A &#8211; S1 * P1_0 &#8211; S3 * P3_0, B2, Q2, R2);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P3 = icare(A &#8211; S1 * P1_0 &#8211; S2 * P2_0, B3, Q3, R3);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Store current values as old for the next iteration<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P1_0 = P1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P2_0 = P2;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> P3_0 = P3;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">At each iteration, each satellite solves a <span style=\"font-weight: bold;\">modified algebraic Riccati equation (CARE)<\/span>.<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">The guessed matrices (P1, P2, P3) are adjusted.<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">This is essentially a <span style=\"font-weight: bold;\">best-response update<\/span>: each player assumes others are fixed and computes its own optimal response.<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">The loop continues until all three matrices stop changing significantly ( the <span style=\"font-family: monospace;\">while <\/span>condition is not satisfied).<\/li>\n<\/ul>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Method 2) Direct Nonlinear System Solver<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>The second approach treats the Riccati system as a single block of nonlinear equations. We parameterize each symmetric matrix using its upper-triangular entries and define a residual function over all unknowns. This results in a system of 3n(n+1)\/2equations and we then solve<\/p>\n<p>F(P<sub>1<\/sub>, P<sub>2<\/sub>, P<sub>3<\/sub>) = 0<\/p>\n<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">using MATLAB <a href=\"https:\/\/uk.mathworks.com\/help\/optim\/ug\/fsolve.html\"><span style=\"font-family: monospace;\">fsolve<\/span><\/a>. Internally, this method:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Encodes each as a vector of unique upper-triangular elements,<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Constructs the residuals of the Riccati equations,<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Uses fsolve to drive the residual norm toward zero,<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Verifies solution symmetry and positive-definiteness.<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">It\u2019s more computationally intensive, but also more general and robust\u2014especially for high-dimensional or ill-conditioned systems. Below is an overview of the code:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Definition of the options for the optimisation problem<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">options = optimoptions(<span style=\"color: #a709f5;\">&#8216;fsolve&#8217;<\/span>, <span style=\"color: #a709f5;\">&#8216;Display&#8217;<\/span>, <span style=\"color: #a709f5;\">&#8216;iter&#8217;<\/span>, <span style=\"color: #a709f5;\">&#8216;Algorithm&#8217;<\/span>, <span style=\"color: #a709f5;\">&#8216;trust-region&#8217;<\/span>, <span style=\"color: #0e00ff;\">&#8230;<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #a709f5;\">&#8216;MaxFunctionEvaluations&#8217;<\/span>, 5000, <span style=\"color: #a709f5;\">&#8216;MaxIterations&#8217;<\/span>, 5000, <span style=\"color: #0e00ff;\">&#8230;<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #a709f5;\">&#8216;FunctionTolerance&#8217;<\/span>, 1e-20,<span style=\"color: #a709f5;\">&#8216;OptimalityTolerance&#8217;<\/span>,1e-10);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Calling function<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">[P1_2, P2_2, P3_2] = solveRiccatiFsolve(A, Q1, Q2, Q3, S1, S2, S3, options);<\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">More specifically:<\/div>\n<ul style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">fsolve attempts to find the roots of the residual equations (i.e., where they evaluate to zero).<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">We use a <span style=\"font-style: italic;\">trust-region<\/span> algorithm, suitable for large systems.<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">A tight tolerance ensures high-accuracy convergence for sensitive Riccati solutions.<\/li>\n<\/ul>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>Going into more details on the function <span style=\"font-family: monospace;\">solveRiccatiFsolve<\/span> note that we take as input the system matrices <span style=\"font-family: STIXGeneral-webfont, serif; font-style: italic; font-weight: 400; color: #212121;\">A<\/span>, cost matrices Q1,Q2 and Q3, and weighting matrices S1,S2 and S3. We also accept optional settings for the optimization routine. Inside the body of the function significant parts of the code are:<\/p>\n<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Initial guess: using pre-defined matrix P<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P1_init = P; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P2_init = P;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">P3_init = P;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Convert initial symmetric matrices to vectors (only unique elements)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0 = zeros(totalVars, 1);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Extract upper triangular elements of P1<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">idx = 1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">for <\/span>i = 1:n<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = i:n<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> x0(idx) = P1_init(i,j);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> idx = idx + 1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Extract upper triangular elements of P2 and P3<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% &#8230; [similar code for P2 and P3]<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>The choice of initial guess is critical for convergence. The initial guess is chosen in the same way as in Method 1). Note that we only extract the upper triangular elements (since the matrices are symmetric) and flatten them into a single vector x0 that fsolve will work with. This vectorization approach is key to using MATLAB&#8217;s optimization tools effectively. Moving on:<\/p>\n<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Define residual function for fsolve<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">resFun = @(x) riccatiResidualVector(x, problem);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Use fsolve to find the root of the residual function<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">[x_sol, fval, exitflag, output] = fsolve(resFun, x0, options);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Convert solution vector back to matrices<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">[P1, P2, P3] = vector2matrices(x_sol, n);<\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This is the heart of our solution method. We create a function handle to our residual calculator and pass it to fsolve, which attempts to find values that make the residual zero. After fsolve completes, we convert the resulting vector back into our three symmetric matrices. The <span style=\"font-family: monospace;\">vector2matrices<\/span> helper function (not shown) reverses the flattening process we did earlier. Let&#8217;s now understand the role of <span style=\"font-family: monospace;\">riccatiResidualVector.<\/span><\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">function <\/span>[resVec] = riccatiResidualVector(x, problem)<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Calculate residual vector for the system of Riccati equations<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Extract problem data<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> A = problem.A;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> Q1 = problem.Q1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% &#8230; [extract other matrices]<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Convert vector to matrices<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> [P1, P2, P3] = vector2matrices(x, n);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Calculate residuals<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> Res1 = P1*A + A&#8217;*P1 + Q1 &#8211; P1*S1*P1 &#8211; P1*S2*P2 &#8211; P1*S3*P3 &#8211; P2*S2*P1 &#8211; P3*S3*P1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> Res2 = P2*A + A&#8217;*P2 + Q2 &#8211; P2*S2*P2 &#8211; P2*S1*P1 &#8211; P2*S3*P3 &#8211; P1*S1*P2 &#8211; P3*S3*P2;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> Res3 = P3*A + A&#8217;*P3 + Q3 &#8211; P3*S3*P3 &#8211; P3*S2*P2 &#8211; P3*S1*P1 &#8211; P2*S2*P3 &#8211; P1*S1*P3;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% Vectorize the residuals (only need upper triangular part due to symmetry)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> resVec = zeros(3 * n * (n+1) \/ 2, 1);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> idx = 1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>i = 1:n<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">for <\/span>j = i:n<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> resVec(idx) = Res1(i,j);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> idx = idx + 1;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"> <span style=\"color: #008013;\">% &#8230; [similar code for Res2 and Res3]<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #0e00ff;\">end<\/span><\/span><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The residual function directly evaluates how far our current solution is from satisfying the coupled Riccati equations. For each proposed solution vector <span style=\"font-family: monospace;\">x<\/span>, we:<\/div>\n<ol style=\"margin: 10px 0px 20px; padding-left: 0px; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-size: 14px;\">\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Convert it back to matrix form<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Evaluate the left-hand side of each equation<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">Since the right-hand side is zero, these values are our residuals<\/li>\n<li style=\"margin-left: 56px; line-height: 21px; min-height: 0px; text-align: left; white-space: pre-wrap;\">We flatten only the upper triangular parts of these residual matrices into a vector<\/li>\n<\/ol>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This function is called repeatedly by fsolve until it finds a solution where all residuals are sufficiently close to zero.<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Simulation Results: <\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>With the feedback matrices P1, P2 and P3 computed, we can now simulate how our satellites behave in closed-loop formation. This is where the theory meets reality.<\/p>\n<\/div>\n<div style=\"margin: 0px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<div style=\"font-family: Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5; color: #212121;\">\n<p>We plug the optimal strategies back into the system. The control law for each satellite is:<\/p>\n<p style=\"margin: 8px 0 8px 20px; font-family: monospace; white-space: nowrap;\">u<sub>i<\/sub><sup>\u22c6<\/sup> = -R<sub>i<\/sub><sup>\u22121<\/sup> B<sub>i<\/sub><sup>\u22a4<\/sup> P<sub>i<\/sub> x<\/p>\n<p>This leads to a closed-loop system of the form:<\/p>\n<p style=\"margin: 8px 0 0 20px; font-family: monospace; white-space: nowrap;\">\u1e8b = (A \u2212 \u2211<sub>i=1<\/sub><sup>3<\/sup> S<sub>i<\/sub> P<sub>i<\/sub>) x<\/p>\n<\/div>\n<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">In MATLAB, we can use the Control system toolbox and specifically <a href=\"https:\/\/uk.mathworks.com\/help\/control\/ref\/ss.html\"><span style=\"font-family: monospace;\">ss<\/span><\/a> and <a href=\"https:\/\/uk.mathworks.com\/help\/control\/ref\/dynamicsystem.initial.html\"><span style=\"font-family: monospace;\">initial<\/span><\/a> to do so:<\/div>\n<div style=\"background-color: #f5f5f5; margin: 10px 15px 10px 0; display: inline-block;\">\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0.666667px solid #d9d9d9; border-bottom: 0px none #212121; border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Define closed-loop system<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">Acl = A &#8211; S1*P1_2 &#8211; S2*P2_2 &#8211; S3*P3_2;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Define state-space system (no inputs, identity output)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">sys = ss(Acl, [], eye(size(Acl,1)), []);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Initial state vector<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0 = zeros(18,1);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(1) = -609.6037;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(2) = -255.3828;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(3) = -255.3828 &#8211; 71.62273;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(7) = -2.6175;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(8) = 136.4284;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(9) = -391.8478;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(13) = 735.5903;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(14) = -441.9009;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">x0(15) = 9.5313;<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\"><span style=\"color: #008013;\">% Simulate initial condition response (error dynamics)<\/span><\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">t = 0:0.1:500; <\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0px none #212121; border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><span style=\"white-space: pre;\">[y, t, x] = initial(sys, x0, t);<\/span><\/div>\n<\/div>\n<div class=\"inlineWrapper\">\n<div style=\"border-left: 0.666667px solid #d9d9d9; border-right: 0.666667px solid #d9d9d9; border-top: 0px none #212121; border-bottom: 0.666667px solid #d9d9d9; border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: #212121; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 14px;\"><\/div>\n<\/div>\n<\/div>\n<div style=\"margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">\n<p>Note that in this specific scenario both methods gave the same solutions for P1\u2009,P2,P3.<\/p>\n<\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">Simulations<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">In the following animations we can visualize the relative position between the satellites, the trajectories of the satellites as well as a 3D recreation of their movements. All plots have been generated using MATLAB libraries and functions (after suitable changes of coordinates).<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\"><\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 400px; height: 305px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/25July28_3.gif\" alt=\"trajectories.gif\" width=\"400\" height=\"305\" \/><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline; width: 397px; height: 310px;\" src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/25July28_4.gif\" alt=\"3Danimationgif.gif\" width=\"397\" height=\"310\" \/><\/div>\n<h2 style=\"margin: 20px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: bold; text-align: left;\"><span style=\"font-weight: bold; text-decoration: underline;\">What the Results Show<\/span><\/h2>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">The satellites begin from significantly offset positions and velocities. But under the Nash-optimal control laws, they rapidly coordinate their motion\u2014balancing <span style=\"font-weight: bold;\">fuel efficiency<\/span> and <span style=\"font-weight: bold;\">formation accuracy<\/span>. The result is <span style=\"font-weight: bold;\">coherent group behavior<\/span>.<\/div>\n<div style=\"margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: #212121; font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;\">This is the power of differential game theory\u2014and MATLAB gives us the tools to simulate and visualize it.<\/div>\n<p><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a href=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/25July28.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/student-lounge\/files\/2025\/07\/Featured-image-gif.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div>\n<p>Today\u2019s guest blogger is Maria Luisa, who\u2019s doing her PhD in Control Systems at Imperial College London and is also one of our MATLAB Student Ambassadors. Over to you, Maria..<br \/>\nIntroduction &amp;&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/student-lounge\/2025\/07\/28\/how-satellites-use-game-theory-to-fly-in-perfect-formation-simulated-in-matlab\/\">read more >><\/a><\/p>\n","protected":false},"author":183,"featured_media":12722,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[730,767,403],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/12719"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/users\/183"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/comments?post=12719"}],"version-history":[{"count":31,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/12719\/revisions"}],"predecessor-version":[{"id":12815,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/posts\/12719\/revisions\/12815"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media\/12722"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/media?parent=12719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/categories?post=12719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/student-lounge\/wp-json\/wp\/v2\/tags?post=12719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}