{"id":45,"date":"2024-08-16T16:36:08","date_gmt":"2024-08-16T16:36:08","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/chapter-4\/"},"modified":"2026-03-16T14:22:57","modified_gmt":"2026-03-16T14:22:57","slug":"chapter-4","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/chapter-4\/","title":{"raw":"Inverse Kinematics and Jacobian for Serial Manipulators","rendered":"Inverse Kinematics and Jacobian for Serial Manipulators"},"content":{"raw":"[latexpage]\n<h1><a id=\"ikexamples\" href=\"\"><\/a>1) Inverse Kinematics<\/h1>\n<h2>Theory<\/h2>\nInverse kinematics (IK) is the mathematical mapping from end effector pose (<em>x, y, z, roll, pitch, yaw)<\/em> to joint positions (<em>d's, $\\theta$'s<\/em>).\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"401\"]<img class=\"wp-image-31\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-300x77.jpg\" alt=\"Inverse Kinematics Diagram\" width=\"401\" height=\"103\"> Figure 4.1: Inverse Kinematics Diagram[\/caption]\n\nSimilarly to forward kinematics, this relationship is independent of force and torque and assumes that each joint in the chain has one degree of freedom (or is two joints).\u00a0 IK is more difficult than FK for serial robots because multiple solutions are possible, but it is easier than FK for parallel robots because only one solution is possible.\n\nThe goal of IK is to find all solutions to the base-to-tip transformation $T_n^0 (\\theta_1,\\theta_2,...\\theta_n) = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $.\u00a0 The method is to take the first three rows of $T_n^0$ and solve for all\u00a0<em>d's\u00a0<\/em>and $\\theta's$.\u00a0 This results in 12 equations (one per element of the reduced 3x4 matrix) and\u00a0<em>n<\/em> unknowns.\u00a0 Typically\u00a0<em>n<\/em> <span style=\"text-decoration: underline;\">&lt;<\/span> 6 so a solution is almost always possible.\u00a0 Closed-form analytical solutions (as opposed to numerical solutions) are ideal.\u00a0 The possible cases for a serial manipulator are:\n<ul>\n \t<li>no solution (point is outside robot's workspace)<\/li>\n \t<li>one solution (point is on edge of workspace)<\/li>\n \t<li>multiple solutions (point is inside workspace)<\/li>\n \t<li>impossible solutions (point is inside workspace but not possible for the end effector to reach at the given orientation, such as points inside the robot itself or that would require to the robot to do contortions)<\/li>\n<\/ul>\nFor a detailed explanation of inverse kinematics, watch the video below.\u00a0 A downloadable slide deck corresponding to the videos but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/IK-Basics-Slides.pdf\" target=\"_blank\" rel=\"noopener\">IK Basics Slides<\/a>\n\nVideo: <a href=\"https:\/\/youtu.be\/qaz5GXvYE3o\">Inverse Kinematics Intro<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/qaz5GXvYE3o[\/embed]\n\nThis theory is applied in examples below showing how to determine the inverse kinematics for two robots, one in 3D space (an RRP Stanford Manipulator), and one in 2D space (an RR planar manipulator).\n<h2>Quick Quiz<\/h2>\nThe original version of this chapter contained H5P content. You may want to remove or replace this element.\n<h2>Examples<\/h2>\nThe video below demonstrates how to solve the inverse kinematics for an RRP Stanford Manipulator.\n\nVideo: <a href=\"https:\/\/youtu.be\/-aOfC9G2C6A\">IK Example - RRP Stanford Manipulator<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/-aOfC9G2C6A[\/embed]\n\nThe video below demonstrates how to solve the inverse kinematics for a 2-link RR manipulator.\n\nVideo: IK Example - <a href=\"https:\/\/youtu.be\/_3Dy30ltDA0\" rel=\"noopener\">Two Link (RR) Manipulator<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/_3Dy30ltDA0[\/embed]\n\n&nbsp;\n<h1>2) Jacobian<\/h1>\n<h2>Theory<\/h2>\nThe Jacobian is a matrix expressing the derivative of end effector position with respect to joint variables:\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"430\"]<img class=\"wp-image-32\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-300x92.jpg\" alt=\"Jacobian\" width=\"430\" height=\"132\"> Figure 4.2: Jacobian[\/caption]\n\nEach element is the derivative of the pose variable with respect to the joint variable corresponding to each row and column.\n<ul>\n \t<li>In 3D space, the Jacobian is a 6x6 matrix.\u00a0 The rows represent the end effector pose variables: x, y, z, roll, pitch, yaw from top to bottom.\u00a0 The columns represent the joint variables: $\\theta$ or\u00a0<em>d<\/em> for each joint.<\/li>\n \t<li>In 2D space, the Jacobian is a 3x3 matrix (or occasionally a 2x2 if there are only 2 joints).\u00a0 The rows represent the end effector pose variables: x, y, and yaw from top to bottom.\u00a0 The columns represent the joint variables: $\\theta$ or <em>d<\/em> for each joint.<\/li>\n<\/ul>\nFor forward and inverse kinematics (position), the Jacobian relates tip pose to joint positions:\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"402\"]<img class=\"wp-image-33\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-300x156.jpg\" alt=\"Kinematics Relationships\" width=\"402\" height=\"209\"> Figure 4.3: Kinematics Relationships[\/caption]\n\nFor derivative kinematics (velocity), the Jacobian relates task space velocities (end effector) to joint space velocities (joints):\n<p style=\"text-align: center;\">$ J \\dot q = \\xi $ or $ J \\dot\\theta = \\dot X $<\/p>\n&nbsp;\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"503\"]<img class=\"wp-image-167\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian_vel-scaled.png\" alt=\"Jacobian and Velocity Relationships\" width=\"503\" height=\"161\"> Figure 4.4: Jacobian and Velocity Relationships[\/caption]\n\nFor a detailed explanation about the Jacobian, watch the video below.\u00a0 A downloadable slide deck corresponding to the video above but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-Theory.pdf\" target=\"_blank\" rel=\"noopener\">Jacobian Theory Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.\n\nVideo: <a href=\"https:\/\/youtu.be\/mBTLWPXTckU\" rel=\"noopener\">Jacobian Introduction<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/mBTLWPXTckU[\/embed]\n\nFor an n-link robot with joint variables $q_1$ ... $q_n$, and a forward kinematics homogeneous transformation matrix $T_n^0$, there are two methods for finding the Jacobian:\n<ol>\n \t<li>Basic method (for simple robots, <em>n<\/em> <span style=\"text-decoration: underline;\">&lt;<\/span> 3)<\/li>\n \t<li>Formula method (for complex robots,\u00a0<em>n<\/em> &gt; 3)<\/li>\n<\/ol>\nThe next sections will walk through the steps to find a Jacobian for a two-link RR robot using first the basic method and then the formula method.\n<h2>Basic Method and Example<\/h2>\nFor an n-link robot with joint variables $q_1$ ... $q_n$, and a forward kinematics base-to-tip homogeneous transformation matrix $T_n^0 = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $, the procedure to solve using the basic method is:\n<ol>\n \t<li>Write position equations for the tip in the world frame (base frame) $o_n^0$<\/li>\n \t<li>Take the derivative to find velocity<\/li>\n \t<li>Put the equations in matrix form $ \\dot X = J \\dot \\theta $<\/li>\n<\/ol>\nThe video below demonstrates how to derive the Jacobian for a 2-link RR manipulator using the <strong>basic method<\/strong>. A downloadable slide deck corresponding to the video example but not annotated is available here:\u00a0<a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/RR-Robot-Jacobian-Basic-Method-Slides.pdf\" target=\"_blank\" rel=\"noopener\">RR-Robot-Jacobian-Basic-Method-Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.\n\nVideo: <a href=\"https:\/\/youtu.be\/YkdMq5WtI4c\" rel=\"noopener\">Two Link RR Manipulator Jacobian Example - Basic Method<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/YkdMq5WtI4c[\/embed]\n<h2>Formula Method and Example<\/h2>\nFor an n-link robot with joint variables $q_1$ ... $q_n$, and a forward kinematics base-to-tip homogeneous transformation matrix $T_n^0 = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $, the procedure to solve using the formula method is:\n\n0. Determine the forward kinematics matrix (if not given).\n1.\u00a0 Write position equations for all joint origins in the world frame $o_i^0$\n2.\u00a0 Write all joint axis vectors $z_i$\n3.\u00a0 Do math by category ($J_v$, $J_\\omega$, revolute joints, prismatic joints) as follows:\n<ul>\n \t<li>For the linear Jacobian $J_v$: assume all joints are fixed and look at the end effector velocity:<\/li>\n<\/ul>\n<p style=\"text-align: center;\">$J_v =\n\\begin{cases}\nz_{i-1} \\times (o_n - o_{i-1}): revolute \\\\\nz_{i-1} : prismatic\n\\end{cases} $<\/p>\n\n<ul>\n \t<li>For the angular Jacobian $J_\\omega$: look at the rotation of frame <em>i<\/em> relative to frame\u00a0<em>i-1 <\/em>:<\/li>\n<\/ul>\n<p style=\"text-align: center;\">$J_\\omega =\n\\begin{cases}\nz_{i-1} : revolute \\\\\n0 \\: (3 \\times 1 \\: matrix) : prismatic\n\\end{cases} $<\/p>\nThe video below demonstrates how to derive the Jacobian for a 2-link RR manipulator using the <strong>formula method<\/strong>.\u00a0 A downloadable slide deck corresponding to the video examples but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/RR-Robot-Jacobian-Formula-Method-Slides-1.pdf\" rel=\"noopener\">RR Robot Jacobian Formula Method Slides<\/a> \u00a0Feel free to print and take notes as you follow along.\n\nVideo: <a href=\"https:\/\/youtu.be\/lfTIxy6-zbA\" rel=\"noopener\">Two Link RR Manipulator - Formula Method<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/lfTIxy6-zbA[\/embed]\n\nThe video below demonstrates how to derive the Jacobian for an RRP SCARA robot using the <strong>formula method<\/strong>.\n\nVideo: <a href=\"https:\/\/youtu.be\/BfTVQQeAeeg\" rel=\"noopener\">RRP Robot Jacobian Example<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/BfTVQQeAeeg[\/embed]\n<h2>Quick Quiz<\/h2>\nThe original version of this chapter contained H5P content. You may want to remove or replace this element.\n<h2>Applications<\/h2>\nThe Jacobian has many applications in robotics.\u00a0 It can be used to:\n<ul>\n \t<li>Find singular configurations of a robot<\/li>\n \t<li>Plan and execute motion trajectories<\/li>\n \t<li>Coordinate motion (position, velocity, and acceleration)<\/li>\n \t<li>Derive dynamic equations of motion<\/li>\n \t<li>Find required joint torque given end effector forces and torques<\/li>\n \t<li>Resolve redundancies (when there are more joints than DoF of the operating space)<\/li>\n<\/ul>\nThe Jacobian can be used with inverse kinematics to determine the required joint speeds to drive a robot's tip at a certain speed.\u00a0 For example, if you are programming a welding robot, and the robot must weld along a line at a constant tip velocity, the joint speeds will not necessarily be constant.\u00a0 However, using the equation $ \\dot q = J^{-1}* \\dot X $, you can calculate the required joint speeds for the entire path.\n\nThe Jacobian can be used with forward kinematics to determine velocity at any point on the robot's arm.\u00a0 In this situation, you would place a point\u00a0<em>p<\/em> at the desired location on the arm to track, and write the Jacobian up to that point using the formula method with <em>p<\/em> instead of $o_n$.\u00a0 Then using the equation $ \\dot X = J \\dot q $, with the new Jacobian, you can determine velocity of the point in question.\n\nThe Jacobian can be used to relate joint torques and end effector forces using the equation $\\tau = J^T F$, where $\\tau$ represents joint torques (n x 1 vector), <em>J<\/em>\u00a0 is the Jacobian (6xn), and <em>F<\/em>\u00a0 is the end effector \"wrench\" (6x1 vector of xyz forces and roll-pitch-yaw torques).\u00a0 The exponent <em>T<\/em> means \"transpose\": switching the rows and columns of a matrix.\u00a0 So to apply a certain force at the end effector, the joint torque can be easily calculated using that formula.\u00a0 To determine force applied for known joint torque, perform the inverse: $F = (J^T)^{-1} * \\tau $.\u00a0 The Jacobian in this instance does not need to be square like it does for kinematics.\n<h1>3) Singularities<\/h1>\n<h2>Theory<\/h2>\nManipulator singularities occur when joint axes align or lock.\u00a0 This is a bad situation!\u00a0 Singularities result in the manipulator losing a degree of freedom and therefore the ability to move in a certain direction at that instant.\u00a0 Bounded end effector velocities result in infinite joint velocities, and bounded joint torques result in unbounded end effector force and torque.\u00a0 Finally, there are infinite possible solutions to the inverse kinematics for that end effector pose.\u00a0 Singularities should be avoided at all costs, otherwise the robot could break.\n\nFor a detailed explanation of robot singularities, watch the video below.\n\nVideo: <a href=\"https:\/\/youtu.be\/vCEWORZbD3Y\" rel=\"noopener\">Robot Singularities<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/vCEWORZbD3Y[\/embed]\n\nIn 2D space, singularities occur when the robot's joint axes lock out, yielding only one solution to the robot's IK.\u00a0 These are points on the edge of the workspace (when the robot is stretched out at full extension), or when two of the links are doubled back on each other, completely aligning.\n\nIn 3D space, singularities occur when joint axes align and there are infinite solutions for the robot's IK.\u00a0 For a standard 6-axis robot, this can occur when joints 1, 4, and 6 (or some combination of those) align.\u00a0 For a visualization of a standard 6R robot moving to near-singularity poses, watch the video below from Mecademic.\n\nVideo: <a href=\"https:\/\/youtu.be\/lD2HQcxeNoA?si=EcDSWt9C3nlz1y0X\" rel=\"noopener\">What are robot singularities?<\/a> by Mecademic\n\n[embed]https:\/\/youtu.be\/lD2HQcxeNoA?si=EcDSWt9C3nlz1y0X[\/embed]\n\nMathematically, singularities occur when the determinant of the Jacobian = 0.\u00a0 So if\u00a0<em>J\u00a0<\/em> = 0, and desired tip speed is a number represented by $\\dot X$, you can see that joint speeds $\\dot q$ would try to shoot to infinity to achieve that in the equation $\\dot X = J \\dot q$.\n\nThere are two methods to find singularities:\n<ol>\n \t<li>Inspection<\/li>\n \t<li>Calculation<\/li>\n<\/ol>\nThese methods are explained below and illustrated with examples.\u00a0 A downloadable slide deck corresponding to these video examples but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Singularity-Examples-Slides.pdf\" rel=\"noopener\">Singularity Examples Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.\n<h2>Examples<\/h2>\nTo solve singularities by calculation,\n<ol>\n \t<li>Write the FK position equations for the robot tip<\/li>\n \t<li>Take the derivative to find velocity<\/li>\n \t<li>Put the velocity equations in matrix form $\\dot X = J \\dot q$<\/li>\n \t<li>Set det(J) = 0 and solve for joint variables\u00a0<em>q<\/em><\/li>\n<\/ol>\nThe video below demonstrates how to find the singularities for a 2-link RR manipulator using math.\n\nVideo: <a href=\"https:\/\/youtu.be\/txTN_kknHDA\" rel=\"noopener\">2-Link RR Manipulator Singularity Example<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/txTN_kknHDA[\/embed]\n\nTo solve singularities by observation:\n<ol>\n \t<li>Look at the robot's joint alignment<\/li>\n \t<li>Visually determine the singularity angles<\/li>\n<\/ol>\nThe video below demonstrates how to find the singularities for two different PR robots by observation and prove them with math.\n\nVideo: <a href=\"https:\/\/youtu.be\/uB2gGXGhvx4\" rel=\"noopener\">PR Robot Singularities<\/a> (click link for closed-caption version)\n\n[embed]https:\/\/youtu.be\/uB2gGXGhvx4[\/embed]\n<h2>Quick Quiz<\/h2>\nThe original version of this chapter contained H5P content. You may want to remove or replace this element.\n<h1>4) MATLAB Programming<\/h1>\nIn order to program a robot to follow a path, knowledge of both the forward and inverse kinematics is necessary.\u00a0 Depending on the degrees of freedom of the robot and dimensions of the operating space (e.g. 2D or 3D), one may be able to control either just position or both position and orientation.\u00a0 A standard 6-axis robot has 6 DoF and operates in 3D space; therefore it is possible to control the entire pose: x\/y\/z position and roll\/pitch\/yaw orientation.\u00a0 (Note that this does not mean all poses are possible; the robot must always operate within its workspace.)\u00a0 For a simpler Cartesian 3P robot (like a 3D printer), it is possible to control x\/y\/z position, but not orientation, because such a robot cannot rotate its end effector.\u00a0 A 2R planar robot can control x\/y position only, due to having only 2 DoF, but a 3R planar robot can control both x\/y position and yaw orientation (angle around z) because it has 3 DoF.\u00a0 For most robots, the number of degrees of freedom corresponds to the number of controllable pose variables.\n\nAs seen above, the inverse kinematics can be solved either algebraically or numerically in order to simulate the robot's motion.\u00a0 If an algebraic solution is possible, this is the more accurate method.\u00a0 If the solution cannot be found algebraically, the Jacobian can be used to solve the joint positions numerically.\u00a0 This is computationally longer and less accurate, but it is a much easier method for solving complicated robots if done in silico (computer program) rather than by hand.\u00a0 The subsections below show how to solve inverse kinematics for a PR robot both algebraically and by hand, and how simulate the robot in MATLAB both ways.\n<h2>Algebraic Solutions<\/h2>\nAn algebraic solution is one in which unknown variables can be solved for manually, and expressions for each unknown variable can be found independent of the others.\u00a0 This method is typically used for simple robots with three or fewer DoF.\u00a0 Examples of algebraic solutions for inverse kinematics are shown above in <a href=\"#ikexamples\">Part 1 of this chapter<\/a>.\n\nFor this example, we will consider a simple PR robot: one prismatic joint and one revolute joint, the first one in <a href=\"https:\/\/youtu.be\/uB2gGXGhvx4\" rel=\"noopener\">PR Robot Singularities<\/a> video above.\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"300\"]<img class=\"wp-image-35 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-300x250.jpg\" alt=\"Planar PR robot\" width=\"300\" height=\"250\"> Figure 4.5: PR Planar Robot[\/caption]\n\nThis robot operates in the YZ plane, where Z points up and Y points to the right.\u00a0 We can write the forward kinematics as follows:\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"550\"]<img class=\"wp-image-36\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-300x179.jpg\" alt=\"PR Forward Kinematics Equations\" width=\"550\" height=\"329\"> Figure 4.6: PR Robot Forward Kinematics Equations[\/caption]\n\nThen we can rearrange these equations to solve for the inverse kinematics algebraically:\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"600\"]<img class=\"wp-image-37\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-300x186.jpg\" alt=\"PR algebraic solution IK\" width=\"600\" height=\"371\"> Figure 4.7: Algebraic Inverse Kinematics Solution for PR Robot[\/caption]\n\nIn order to simulate the robot with a computer program, the following steps are required, and can be used as an outline for the code:\n<ul>\n \t<li>Define knowns, constants, and desired end effector path (x\/y\/z\/roll\/pitch\/yaw, whatever is applicable)<\/li>\n \t<li>Preallocate arrays to store calculated values for the IK<\/li>\n \t<li>Begin a for loop to start calculations for each frame\n<ul>\n \t<li>Calculate the joint values (IK) using the algebraic equations derived<\/li>\n \t<li>Calculate the joint and tip locations in space using FK equations<\/li>\n \t<li>Define arrays of points to plot (matrices of x, y, and z points)<\/li>\n \t<li>Plot the robot<\/li>\n<\/ul>\n<\/li>\n \t<li>End the for loop<\/li>\n<\/ul>\nAn example code using the algebraic method to simulate the PR robot is shown below.\u00a0 This book software cannot read or attach .m files, so a downloadable version is not possible, but you may copy and paste from the textbox.\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\n<p class=\"textbox__title\">Example Algebraic Code for PR Robot Simulation<\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n\n<span style=\"color: #339966;\"><code>%% PR manipulator simulation (Algebraic solution)<\/code><\/span>\n<span style=\"color: #339966;\"><code>% PR robot tracing path<\/code><\/span>\n<span style=\"color: #339966;\"><code>% Robot operates in YZ plane<\/code><\/span>\n<span style=\"color: #339966;\"><code>% Elissa Ledoux ENGR 4501 Spring 2025<\/code><\/span>\n\n<code>clc<\/code>\n<code>clear<\/code>\n<code>close all<\/code>\n\n<span style=\"color: #339966;\"><code>% define constants (arbitrary if not given)<\/code><\/span>\n<code>r = 0.5; % link lengths (m)<\/code>\n<code>nsteps = 50; % number of steps<\/code>\n\n<span style=\"color: #339966;\"><code>% define desired path for end effector (m)<\/code><\/span>\n<code>ystart = 0.5; <\/code>\n<code>ystop = -0.48;<\/code>\n<code>pdesy = linspace(ystart,ystop,nsteps);<\/code>\n<code>pdesz = .7 - (pdesy-0.1).^2; % path option 1\n<span style=\"color: #339966;\">% pdesz = 0.5 + 0.2*sin(pdesy*10*pi); % path option 2<\/span><\/code>\n<code>pdes = [pdesy;pdesz]; % waypoints (m)<\/code>\n\n<span style=\"color: #339966;\"><code>% preallocate arrays<\/code><\/span>\n<code>tip = zeros(2,nsteps); % actual tip path (y and z)<\/code>\n<code>d = zeros(nsteps,1); % prismatic joint<\/code>\n<code>th = zeros(nsteps,1); % revolute joint<\/code>\n\n<span style=\"color: #339966;\"><code>% calculate kinematics<\/code><\/span>\n<code><span style=\"color: #0000ff;\">for<\/span> i = 1:nsteps<\/code>\n\n<span style=\"color: #339966;\"><code>% solve algebraically<\/code><\/span>\n<code>th(i) = acos(pdesy(i)\/r);<\/code>\n<code>d(i) = pdesz(i) - r*sin(th(i));<\/code>\n\n<span style=\"color: #339966;\"><code>% check solution<\/code><\/span>\n<code>y = r*cos(th(i));<\/code>\n<code>z = d(i) + r*sin(th(i));<\/code>\n\n<span style=\"color: #339966;\"><code>% calculate points to plot (location of each joint)<\/code><\/span>\n<code>tip(:,i) = [y;z];<\/code>\n<code>j1y = 0; j1z = 0; % joint 1<\/code>\n<code>j2y = 0; j2z = d(i); % joint 2<\/code>\n<code>jey = r*cos(th(i)); jez = d(i)+r*sin(th(i)); % end effector<\/code>\n<code>Y = [j1y, j2y, jey];<\/code>\n<code>Z = [j1z, j2z, jez];<\/code>\n\n<span style=\"color: #339966;\"><code>% plot robot<\/code><\/span>\n<code>figure(1)<\/code>\n<code>clf<\/code>\n<code>hold on<\/code>\n<code>plot([j1y,j2y],[j1z,j2z],'k','LineWidth',3)<\/code>\n<code>plot([j2y,jey],[j2z,jez],'r','LineWidth',3)<\/code>\n<code>plot(j1y,j1z,'ksq','MarkerSize',10,'MarkerFaceColor','k')<\/code>\n<code>plot(j2y,j2z,'ro','MarkerSize',10,'MarkerFaceColor','r')<\/code>\n<code>plot(jey,jez,'b*','MarkerSize',10)<\/code>\n<code>plot(tip(1,1:i),tip(2,1:i),'b')<\/code>\n<code>xlim([-1 1]); xlabel('Y (m)')<\/code>\n<code>ylim([-.5 1.5]); ylabel('Z (m)')<\/code>\n<code>axis square<\/code>\n<code>title('PR Planar Manipulator')<\/code>\n\n<span style=\"color: #0000ff;\"><code>end<\/code><\/span>\n\n<\/div>\n<\/div>\n<h2><a id=\"numerical\" href=\"\"><\/a>Numerical Solutions<\/h2>\nA numerical solution is one in which unknown variables cannot be solved for manually, and rather are done using the guess-and-check method known as \"Newton's method\" or the \"Newton-Rhapson method.\"\u00a0 This method is typically used for complicated robots with three or more DoF.\u00a0 A numerical solution is done using the robot's Jacobian to iteratively guide guesses for the joint values to until they converge, resulting in a solution for the IK.\u00a0 <strong>IF YOU ARE NEW TO NEWTON'S METHOD, STUDY <a href=\"#newton\">SECTION 5 BELOW<\/a> BEFORE PROCEEDING SO YOU WILL NOT BE UTTERLY LOST.<\/strong>\n\nFor this example, we will consider a the same RP robot as before, with the same forward kinematics, and solve for the inverse kinematics numerically using a while loop (guess-and-check while error is greater than a tolerance value and the solution for joint positions converges).\u00a0 This requires deriving the Jacobian of the robot by hand and choosing an initial guess for the joint values before using a computer program to solve the system numerically.\u00a0 The velocity, Jacobian, and guess iteration formulas for this PR robot are shown in the figure below:\n\n[caption id=\"attachment_38\" align=\"aligncenter\" width=\"600\"]<img class=\"wp-image-38\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-300x225.jpg\" alt=\"PR robot velocity and Jacobian\" width=\"600\" height=\"450\"> Figure 4.8: Jacobian and Velocity Kinematics Equations of the PR Robot[\/caption]\n\n<span style=\"text-align: initial; font-size: 1em;\">In order to simulate the robot with a computer program, the following process is required (similarly to the algebraic solution but with additional steps), and can be used as an outline for the code:<\/span>\n<ul>\n \t<li>Define knowns, constants, and desired end effector path (x\/y\/z\/roll\/pitch\/yaw, whatever is applicable)<\/li>\n \t<li>Preallocate arrays to store calculated values for the IK<\/li>\n \t<li>Choose initial guesses for the joint values (these <span style=\"text-decoration: underline;\">must<\/span> be reasonably accurate or the program will get stuck in an infinite loop and never solve.\u00a0 I.e. ensure $\\theta$ is in the correct quadrant and $d$ is on the correct order of magnitude)<\/li>\n \t<li>Begin a for loop to start calculations for each frame\n<ul>\n \t<li>Find the current tip position\u00a0<em>F<\/em> using FK based on the initial guesses<\/li>\n \t<li>Calculate the magnitude of position error<\/li>\n \t<li>Start a while loop to iterate guesses\n<ul>\n \t<li>Calculate the Jacobian using the current guesses<\/li>\n \t<li>Calculate new joint values using $\\theta_{new} = \\theta{old} - J^{-1}F$<\/li>\n \t<li>Find the new tip position using FK based on the new guesses<\/li>\n \t<li>Calculate the magnitude of position error<\/li>\n<\/ul>\n<\/li>\n \t<li>Exit the while loop once guesses are close enough (error within tolerance)<\/li>\n \t<li>Calculate the joint and tip locations in space using FK equations with the correct guesses<\/li>\n \t<li>Define arrays of points to plot (matrices of x, y, and z points)<\/li>\n \t<li>Plot the robot<\/li>\n<\/ul>\n<\/li>\n \t<li>End the for loop<\/li>\n<\/ul>\nAn example code using the numerical method to simulate the PR robot is shown below.\u00a0 This book software cannot read or attach .m files, so a downloadable version is not possible, but you may copy and paste from the textbox.\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\n<p class=\"textbox__title\">Example Numerical Code for PR Robot Simulation<\/p>\n\n<\/header>\n<div class=\"textbox__content\">\n\n<span style=\"color: #339966;\"><code>%% PR manipulator simulation (Numerical Solution)<\/code><\/span>\n<span style=\"color: #339966;\"><code>% PR robot tracing path<\/code><\/span>\n<span style=\"color: #339966;\"><code>% Robot operates in YZ plane<\/code><\/span>\n<span style=\"color: #339966;\"><code>% Elissa Ledoux ENGR 4501 Spring 2025<\/code><\/span>\n\n<code>clc<\/code>\n<code>clear<\/code>\n<code>close all<\/code>\n\n<span style=\"color: #339966;\"><code>% define constants (arbitrary if not given)<\/code><\/span>\n<code>r = 0.5; % link lengths (m)<\/code>\n<code>nsteps = 50; % number of steps<\/code>\n<code>dt = 0.1; % timestep<\/code>\n<code>vee = 1; % end effector velocity (m\/s)<\/code>\n<code>tol = 10^(-3); % accuracy tolerance (m)<\/code>\n\n<span style=\"color: #339966;\"><code>% define desired path for end effector (m)<\/code><\/span>\n<code>ystart = 0.5; <\/code>\n<code>ystop = -0.48;<\/code>\n<code>pdesy = linspace(ystart,ystop,nsteps);<\/code>\n<code>pdesz = .7 - (pdesy-0.1).^2; % path option 1<\/code>\n<code>% pdesz = 0.5 + 0.2*sin(pdesy*10*pi); % path option 2<\/code>\n<code>pdes = [pdesy;pdesz]; % waypoints (m)<\/code>\n\n<span style=\"color: #339966;\"><code>% preallocate arrays<\/code><\/span>\n<code>tip = zeros(2,nsteps); % actual tip path (y and z)<\/code>\n<code>d = zeros(nsteps,1); % prismatic joint<\/code>\n<code>th = zeros(nsteps,1); % revolute joint<\/code>\n\n<span style=\"color: #339966;\"><code>% initial guesses (joint positions)<\/code><\/span>\n<code>d_guess = 0.2; d(1) = d_guess;<\/code>\n<code>th_guess = pi\/10; th(1) = th_guess;<\/code>\n\n<span style=\"color: #339966;\"><code>% calculate kinematics<\/code><\/span>\n<code><span style=\"color: #0000ff;\">for<\/span> i = 1:nsteps<\/code>\n<code>c = 0; % counter<\/code>\n\n<span style=\"color: #339966;\"><code>% find current point using FK (use basic, DH, or product of exp method)<\/code><\/span>\n<code>y = r*cos(th(i));<\/code>\n<code>z = d(i) + r*sin(th(i));<\/code>\n<code>pcur = [y;z];<\/code>\n\n<span style=\"color: #339966;\"><code>% find error<\/code><\/span>\n<code>errvec = pdes(:,i)-pcur;<\/code>\n<code>err = norm(errvec);<\/code>\n\n<span style=\"color: #339966;\"><code>% solve numerically (guess-and-check Newton's method)<\/code><\/span>\n<code><span style=\"color: #0000ff;\">while<\/span> err &gt; tol <\/code>\n\n<span style=\"color: #339966;\"><code>% find Jacobian (2D) (use basic or formula method)<\/code><\/span>\n<code>J = [0, -r*sin(th_guess); ...<\/code>\n<code>1, r*cos(th_guess)];<\/code>\n\n<span style=\"color: #339966;\"><code>% find velocities of end effector and joints<\/code><\/span>\n<code>xdot = vee*errvec;<\/code>\n<code>qdot = J\\xdot;<\/code>\n\n<span style=\"color: #339966;\"><code>% calculate new joint positions<\/code><\/span>\n<code>q = [d_guess; th_guess]+qdot*dt;<\/code>\n<code>d_guess = q(1); th_guess = q(2);<\/code>\n\n<span style=\"color: #339966;\"><code>% find current point using FK (use basic, DH, or product of exp)<\/code><\/span>\n<code>y = r*cos(th_guess);<\/code>\n<code>z = d_guess + r*sin(th_guess);<\/code>\n<code>pcur = [y;z];<\/code>\n\n<span style=\"color: #339966;\"><code>% find error<\/code><\/span>\n<code>errvec = pdes(:,i)-pcur;<\/code>\n<code>err = norm(errvec);<\/code>\n\n<span style=\"color: #339966;\"><code>% update counter<\/code><\/span>\n<code>c = c+1;<\/code>\n<span style=\"color: #0000ff;\"><code>end<\/code><\/span>\n\n<span style=\"color: #339966;\"><code>% save correct joint positions<\/code><\/span>\n<code>d(i) = d_guess;<\/code>\n<code>th(i) = th_guess;<\/code>\n\n<span style=\"color: #339966;\"><code>% calculate points to plot (location of each joint)<\/code><\/span>\n<code>tip(:,i) = [y;z];<\/code>\n<code>j1y = 0; j1z = 0; % joint 1<\/code>\n<code>j2y = 0; j2z = d(i); % joint 2<\/code>\n<code>jey = r*cos(th(i)); jez = d(i)+r*sin(th(i)); % end effector<\/code>\n<code>Y = [j1y, j2y, jey];<\/code>\n<code>Z = [j1z, j2z, jez];<\/code>\n\n<span style=\"color: #339966;\"><code>% plot robot<\/code><\/span>\n<code>figure(1)<\/code>\n<code>clf<\/code>\n<code>hold on<\/code>\n<code>plot([j1y,j2y],[j1z,j2z],'k','LineWidth',3)<\/code>\n<code>plot([j2y,jey],[j2z,jez],'r','LineWidth',3)<\/code>\n<code>plot(j1y,j1z,'ksq','MarkerSize',10,'MarkerFaceColor','k')<\/code>\n<code>plot(j2y,j2z,'ro','MarkerSize',10,'MarkerFaceColor','r')<\/code>\n<code>plot(jey,jez,'b*','MarkerSize',10)<\/code>\n<code>plot(tip(1,1:i),tip(2,1:i),'b')<\/code>\n<code>xlim([-1 1]); xlabel('Y (m)')<\/code>\n<code>ylim([-.5 1.5]); ylabel('Z (m)')<\/code>\n<code>axis square<\/code>\n<code>title('PR Planar Manipulator')<\/code>\n\n<span style=\"color: #0000ff;\"><code>end<\/code><\/span>\n\n<\/div>\n<\/div>\nA more detailed and downloadable outline for code logic including pose control (position and orientation both) is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Pose-Control-Logic.pdf\" rel=\"noopener\">Pose Control Logic<\/a>\n<h1><a id=\"newton\" href=\"\"><\/a>5) Review of Newton's Method for Numerical Solutions<\/h1>\nNewton's method, or the Newton-Rhapson method, is a way to solve equations numerically, by finding roots or unknowns of a function or system of equations using a guess-and-check procedure.\u00a0 In advanced kinematics courses, it is used to solve and simulate mechanisms such as closed-chain or hybrid-chain linkages using vector loop equations.\u00a0 In robotics, Newton's method can also be used to simulate both parallel and serial robots using forward and inverse kinematics.\n\nThe basic process is:\n<ol>\n \t<li>Make an initial guess<em>G <\/em>of values for the unknown variables<\/li>\n \t<li>Calculate the value of the function <em>F <\/em>using the guess\u00a0<em>G<\/em><\/li>\n \t<li>Check if the function value <em>F<\/em>\u00a0nears zero.\u00a0 If so, stop.\u00a0 The guess is correct.\u00a0 If not, continue to step 4.<\/li>\n \t<li>Calculate the derivative (Jacobian) <em>J<\/em> of the function and plug in the guess values.<\/li>\n \t<li>Calculate a new guess <em>G <\/em>using the formula $G = G - J^{-1}F$<\/li>\n \t<li>Repeat steps 2-5 until solved<\/li>\n<\/ol>\nAn explanation of the theory as well as a simple example using a scalar equation and single unknown variable is in this video: <a href=\"https:\/\/youtu.be\/RPtpDQHgvk0\">Newton's Method Explained + Example<\/a>.\n\nThe process above can be followed to solve the equation using a computer program rather than by hand.\u00a0 A video tutorial on how to do this is here: <a href=\"https:\/\/youtu.be\/1srF-6GLRMU\">Programming Newton's Method in MATLAB<\/a>.\n\nIf more than one variable must be solved for, such as multiple unknown joint values of a robot, matrices must be used instead of scalars.\u00a0 An explanation of how to set up matrices for a system of two equations and two unknowns for a parallel closed-chain mechanism is in this video: <a href=\"https:\/\/youtu.be\/1d7bTylFuBM\">Four Bar Linkage Solution Newton's Method.<\/a>\n\nThis completes the review, and you are now ready to return to <a href=\"#numerical\">Part 4 of this chapter<\/a> to solve and simulate a robot in Matlab numerically.","rendered":"<p>[latexpage]<\/p>\n<h1><a id=\"ikexamples\" href=\"\"><\/a>1) Inverse Kinematics<\/h1>\n<h2>Theory<\/h2>\n<p>Inverse kinematics (IK) is the mathematical mapping from end effector pose (<em>x, y, z, roll, pitch, yaw)<\/em> to joint positions (<em>d&#8217;s, $\\theta$&#8217;s<\/em>).<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 401px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-31\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-300x77.jpg\" alt=\"Inverse Kinematics Diagram\" width=\"401\" height=\"103\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-300x77.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-1024x263.jpg 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-768x198.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-1536x395.jpg 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-65x17.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-225x58.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK-350x90.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2024\/08\/IK.jpg 1854w\" sizes=\"(max-width: 401px) 100vw, 401px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.1: Inverse Kinematics Diagram<\/figcaption><\/figure>\n<p>Similarly to forward kinematics, this relationship is independent of force and torque and assumes that each joint in the chain has one degree of freedom (or is two joints).\u00a0 IK is more difficult than FK for serial robots because multiple solutions are possible, but it is easier than FK for parallel robots because only one solution is possible.<\/p>\n<p>The goal of IK is to find all solutions to the base-to-tip transformation $T_n^0 (\\theta_1,\\theta_2,&#8230;\\theta_n) = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $.\u00a0 The method is to take the first three rows of $T_n^0$ and solve for all\u00a0<em>d&#8217;s\u00a0<\/em>and $\\theta&#8217;s$.\u00a0 This results in 12 equations (one per element of the reduced 3&#215;4 matrix) and\u00a0<em>n<\/em> unknowns.\u00a0 Typically\u00a0<em>n<\/em> <span style=\"text-decoration: underline;\">&lt;<\/span> 6 so a solution is almost always possible.\u00a0 Closed-form analytical solutions (as opposed to numerical solutions) are ideal.\u00a0 The possible cases for a serial manipulator are:<\/p>\n<ul>\n<li>no solution (point is outside robot&#8217;s workspace)<\/li>\n<li>one solution (point is on edge of workspace)<\/li>\n<li>multiple solutions (point is inside workspace)<\/li>\n<li>impossible solutions (point is inside workspace but not possible for the end effector to reach at the given orientation, such as points inside the robot itself or that would require to the robot to do contortions)<\/li>\n<\/ul>\n<p>For a detailed explanation of inverse kinematics, watch the video below.\u00a0 A downloadable slide deck corresponding to the videos but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/IK-Basics-Slides.pdf\" target=\"_blank\" rel=\"noopener\">IK Basics Slides<\/a><\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/qaz5GXvYE3o\">Inverse Kinematics Intro<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-1\" title=\"Inverse Kinematics Intro\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/qaz5GXvYE3o?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>This theory is applied in examples below showing how to determine the inverse kinematics for two robots, one in 3D space (an RRP Stanford Manipulator), and one in 2D space (an RR planar manipulator).<\/p>\n<h2>Quick Quiz<\/h2>\n<p>The original version of this chapter contained H5P content. You may want to remove or replace this element.<\/p>\n<h2>Examples<\/h2>\n<p>The video below demonstrates how to solve the inverse kinematics for an RRP Stanford Manipulator.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/-aOfC9G2C6A\">IK Example &#8211; RRP Stanford Manipulator<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-2\" title=\"IK Example - RRP Stanford Manipulator\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/-aOfC9G2C6A?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>The video below demonstrates how to solve the inverse kinematics for a 2-link RR manipulator.<\/p>\n<p>Video: IK Example &#8211; <a href=\"https:\/\/youtu.be\/_3Dy30ltDA0\" rel=\"noopener\">Two Link (RR) Manipulator<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-3\" title=\"IK Example - Two Link (RR) Manipulator\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/_3Dy30ltDA0?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<h1>2) Jacobian<\/h1>\n<h2>Theory<\/h2>\n<p>The Jacobian is a matrix expressing the derivative of end effector position with respect to joint variables:<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 430px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-32\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-300x92.jpg\" alt=\"Jacobian\" width=\"430\" height=\"132\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-300x92.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-1024x314.jpg 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-768x236.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-1536x471.jpg 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-2048x628.jpg 2048w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-65x20.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-225x69.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-350x107.jpg 350w\" sizes=\"(max-width: 430px) 100vw, 430px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.2: Jacobian<\/figcaption><\/figure>\n<p>Each element is the derivative of the pose variable with respect to the joint variable corresponding to each row and column.<\/p>\n<ul>\n<li>In 3D space, the Jacobian is a 6&#215;6 matrix.\u00a0 The rows represent the end effector pose variables: x, y, z, roll, pitch, yaw from top to bottom.\u00a0 The columns represent the joint variables: $\\theta$ or\u00a0<em>d<\/em> for each joint.<\/li>\n<li>In 2D space, the Jacobian is a 3&#215;3 matrix (or occasionally a 2&#215;2 if there are only 2 joints).\u00a0 The rows represent the end effector pose variables: x, y, and yaw from top to bottom.\u00a0 The columns represent the joint variables: $\\theta$ or <em>d<\/em> for each joint.<\/li>\n<\/ul>\n<p>For forward and inverse kinematics (position), the Jacobian relates tip pose to joint positions:<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 402px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-33\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-300x156.jpg\" alt=\"Kinematics Relationships\" width=\"402\" height=\"209\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-300x156.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-1024x533.jpg 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-768x400.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-65x34.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-225x117.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK-350x182.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/FK-and-IK.jpg 1448w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.3: Kinematics Relationships<\/figcaption><\/figure>\n<p>For derivative kinematics (velocity), the Jacobian relates task space velocities (end effector) to joint space velocities (joints):<\/p>\n<p style=\"text-align: center;\">$ J \\dot q = \\xi $ or $ J \\dot\\theta = \\dot X $<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 503px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-167\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian_vel-scaled.png\" alt=\"Jacobian and Velocity Relationships\" width=\"503\" height=\"161\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.4: Jacobian and Velocity Relationships<\/figcaption><\/figure>\n<p>For a detailed explanation about the Jacobian, watch the video below.\u00a0 A downloadable slide deck corresponding to the video above but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Jacobian-Theory.pdf\" target=\"_blank\" rel=\"noopener\">Jacobian Theory Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/mBTLWPXTckU\" rel=\"noopener\">Jacobian Introduction<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-4\" title=\"Jacobian Introduction\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/mBTLWPXTckU?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>For an n-link robot with joint variables $q_1$ &#8230; $q_n$, and a forward kinematics homogeneous transformation matrix $T_n^0$, there are two methods for finding the Jacobian:<\/p>\n<ol>\n<li>Basic method (for simple robots, <em>n<\/em> <span style=\"text-decoration: underline;\">&lt;<\/span> 3)<\/li>\n<li>Formula method (for complex robots,\u00a0<em>n<\/em> &gt; 3)<\/li>\n<\/ol>\n<p>The next sections will walk through the steps to find a Jacobian for a two-link RR robot using first the basic method and then the formula method.<\/p>\n<h2>Basic Method and Example<\/h2>\n<p>For an n-link robot with joint variables $q_1$ &#8230; $q_n$, and a forward kinematics base-to-tip homogeneous transformation matrix $T_n^0 = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $, the procedure to solve using the basic method is:<\/p>\n<ol>\n<li>Write position equations for the tip in the world frame (base frame) $o_n^0$<\/li>\n<li>Take the derivative to find velocity<\/li>\n<li>Put the equations in matrix form $ \\dot X = J \\dot \\theta $<\/li>\n<\/ol>\n<p>The video below demonstrates how to derive the Jacobian for a 2-link RR manipulator using the <strong>basic method<\/strong>. A downloadable slide deck corresponding to the video example but not annotated is available here:\u00a0<a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/RR-Robot-Jacobian-Basic-Method-Slides.pdf\" target=\"_blank\" rel=\"noopener\">RR-Robot-Jacobian-Basic-Method-Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/YkdMq5WtI4c\" rel=\"noopener\">Two Link RR Manipulator Jacobian Example &#8211; Basic Method<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-5\" title=\"Two Link RR Manipulator Jacobian Example - Basic Method\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/YkdMq5WtI4c?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Formula Method and Example<\/h2>\n<p>For an n-link robot with joint variables $q_1$ &#8230; $q_n$, and a forward kinematics base-to-tip homogeneous transformation matrix $T_n^0 = \\begin{bmatrix} R_n^0 &amp; o_n^0 \\\\ 0 &amp; 1 \\end{bmatrix} $, the procedure to solve using the formula method is:<\/p>\n<p>0. Determine the forward kinematics matrix (if not given).<br \/>\n1.\u00a0 Write position equations for all joint origins in the world frame $o_i^0$<br \/>\n2.\u00a0 Write all joint axis vectors $z_i$<br \/>\n3.\u00a0 Do math by category ($J_v$, $J_\\omega$, revolute joints, prismatic joints) as follows:<\/p>\n<ul>\n<li>For the linear Jacobian $J_v$: assume all joints are fixed and look at the end effector velocity:<\/li>\n<\/ul>\n<p style=\"text-align: center;\">$J_v =<br \/>\n\\begin{cases}<br \/>\nz_{i-1} \\times (o_n &#8211; o_{i-1}): revolute \\\\<br \/>\nz_{i-1} : prismatic<br \/>\n\\end{cases} $<\/p>\n<ul>\n<li>For the angular Jacobian $J_\\omega$: look at the rotation of frame <em>i<\/em> relative to frame\u00a0<em>i-1 <\/em>:<\/li>\n<\/ul>\n<p style=\"text-align: center;\">$J_\\omega =<br \/>\n\\begin{cases}<br \/>\nz_{i-1} : revolute \\\\<br \/>\n0 \\: (3 \\times 1 \\: matrix) : prismatic<br \/>\n\\end{cases} $<\/p>\n<p>The video below demonstrates how to derive the Jacobian for a 2-link RR manipulator using the <strong>formula method<\/strong>.\u00a0 A downloadable slide deck corresponding to the video examples but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/RR-Robot-Jacobian-Formula-Method-Slides-1.pdf\" rel=\"noopener\">RR Robot Jacobian Formula Method Slides<\/a> \u00a0Feel free to print and take notes as you follow along.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/lfTIxy6-zbA\" rel=\"noopener\">Two Link RR Manipulator &#8211; Formula Method<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-6\" title=\"Two Link RR Manipulator Jacobian Example - Formula Method\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/lfTIxy6-zbA?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>The video below demonstrates how to derive the Jacobian for an RRP SCARA robot using the <strong>formula method<\/strong>.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/BfTVQQeAeeg\" rel=\"noopener\">RRP Robot Jacobian Example<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-7\" title=\"RRP Robot Jacobian Example\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/BfTVQQeAeeg?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Quick Quiz<\/h2>\n<p>The original version of this chapter contained H5P content. You may want to remove or replace this element.<\/p>\n<h2>Applications<\/h2>\n<p>The Jacobian has many applications in robotics.\u00a0 It can be used to:<\/p>\n<ul>\n<li>Find singular configurations of a robot<\/li>\n<li>Plan and execute motion trajectories<\/li>\n<li>Coordinate motion (position, velocity, and acceleration)<\/li>\n<li>Derive dynamic equations of motion<\/li>\n<li>Find required joint torque given end effector forces and torques<\/li>\n<li>Resolve redundancies (when there are more joints than DoF of the operating space)<\/li>\n<\/ul>\n<p>The Jacobian can be used with inverse kinematics to determine the required joint speeds to drive a robot&#8217;s tip at a certain speed.\u00a0 For example, if you are programming a welding robot, and the robot must weld along a line at a constant tip velocity, the joint speeds will not necessarily be constant.\u00a0 However, using the equation $ \\dot q = J^{-1}* \\dot X $, you can calculate the required joint speeds for the entire path.<\/p>\n<p>The Jacobian can be used with forward kinematics to determine velocity at any point on the robot&#8217;s arm.\u00a0 In this situation, you would place a point\u00a0<em>p<\/em> at the desired location on the arm to track, and write the Jacobian up to that point using the formula method with <em>p<\/em> instead of $o_n$.\u00a0 Then using the equation $ \\dot X = J \\dot q $, with the new Jacobian, you can determine velocity of the point in question.<\/p>\n<p>The Jacobian can be used to relate joint torques and end effector forces using the equation $\\tau = J^T F$, where $\\tau$ represents joint torques (n x 1 vector), <em>J<\/em>\u00a0 is the Jacobian (6xn), and <em>F<\/em>\u00a0 is the end effector &#8220;wrench&#8221; (6&#215;1 vector of xyz forces and roll-pitch-yaw torques).\u00a0 The exponent <em>T<\/em> means &#8220;transpose&#8221;: switching the rows and columns of a matrix.\u00a0 So to apply a certain force at the end effector, the joint torque can be easily calculated using that formula.\u00a0 To determine force applied for known joint torque, perform the inverse: $F = (J^T)^{-1} * \\tau $.\u00a0 The Jacobian in this instance does not need to be square like it does for kinematics.<\/p>\n<h1>3) Singularities<\/h1>\n<h2>Theory<\/h2>\n<p>Manipulator singularities occur when joint axes align or lock.\u00a0 This is a bad situation!\u00a0 Singularities result in the manipulator losing a degree of freedom and therefore the ability to move in a certain direction at that instant.\u00a0 Bounded end effector velocities result in infinite joint velocities, and bounded joint torques result in unbounded end effector force and torque.\u00a0 Finally, there are infinite possible solutions to the inverse kinematics for that end effector pose.\u00a0 Singularities should be avoided at all costs, otherwise the robot could break.<\/p>\n<p>For a detailed explanation of robot singularities, watch the video below.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/vCEWORZbD3Y\" rel=\"noopener\">Robot Singularities<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-8\" title=\"Robot Singularities\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/vCEWORZbD3Y?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>In 2D space, singularities occur when the robot&#8217;s joint axes lock out, yielding only one solution to the robot&#8217;s IK.\u00a0 These are points on the edge of the workspace (when the robot is stretched out at full extension), or when two of the links are doubled back on each other, completely aligning.<\/p>\n<p>In 3D space, singularities occur when joint axes align and there are infinite solutions for the robot&#8217;s IK.\u00a0 For a standard 6-axis robot, this can occur when joints 1, 4, and 6 (or some combination of those) align.\u00a0 For a visualization of a standard 6R robot moving to near-singularity poses, watch the video below from Mecademic.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/lD2HQcxeNoA?si=EcDSWt9C3nlz1y0X\" rel=\"noopener\">What are robot singularities?<\/a> by Mecademic<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-9\" title=\"What are robot singularities?\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/lD2HQcxeNoA?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Mathematically, singularities occur when the determinant of the Jacobian = 0.\u00a0 So if\u00a0<em>J\u00a0<\/em> = 0, and desired tip speed is a number represented by $\\dot X$, you can see that joint speeds $\\dot q$ would try to shoot to infinity to achieve that in the equation $\\dot X = J \\dot q$.<\/p>\n<p>There are two methods to find singularities:<\/p>\n<ol>\n<li>Inspection<\/li>\n<li>Calculation<\/li>\n<\/ol>\n<p>These methods are explained below and illustrated with examples.\u00a0 A downloadable slide deck corresponding to these video examples but not annotated is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Singularity-Examples-Slides.pdf\" rel=\"noopener\">Singularity Examples Slides<\/a>\u00a0 Feel free to print and take notes as you follow along.<\/p>\n<h2>Examples<\/h2>\n<p>To solve singularities by calculation,<\/p>\n<ol>\n<li>Write the FK position equations for the robot tip<\/li>\n<li>Take the derivative to find velocity<\/li>\n<li>Put the velocity equations in matrix form $\\dot X = J \\dot q$<\/li>\n<li>Set det(J) = 0 and solve for joint variables\u00a0<em>q<\/em><\/li>\n<\/ol>\n<p>The video below demonstrates how to find the singularities for a 2-link RR manipulator using math.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/txTN_kknHDA\" rel=\"noopener\">2-Link RR Manipulator Singularity Example<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-10\" title=\"Two Link RR Manipulator Singularity Example\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/txTN_kknHDA?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>To solve singularities by observation:<\/p>\n<ol>\n<li>Look at the robot&#8217;s joint alignment<\/li>\n<li>Visually determine the singularity angles<\/li>\n<\/ol>\n<p>The video below demonstrates how to find the singularities for two different PR robots by observation and prove them with math.<\/p>\n<p>Video: <a href=\"https:\/\/youtu.be\/uB2gGXGhvx4\" rel=\"noopener\">PR Robot Singularities<\/a> (click link for closed-caption version)<\/p>\n<p><iframe loading=\"lazy\" id=\"oembed-11\" title=\"RP Robot Singularities\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/uB2gGXGhvx4?feature=oembed&#38;rel=0\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<h2>Quick Quiz<\/h2>\n<p>The original version of this chapter contained H5P content. You may want to remove or replace this element.<\/p>\n<h1>4) MATLAB Programming<\/h1>\n<p>In order to program a robot to follow a path, knowledge of both the forward and inverse kinematics is necessary.\u00a0 Depending on the degrees of freedom of the robot and dimensions of the operating space (e.g. 2D or 3D), one may be able to control either just position or both position and orientation.\u00a0 A standard 6-axis robot has 6 DoF and operates in 3D space; therefore it is possible to control the entire pose: x\/y\/z position and roll\/pitch\/yaw orientation.\u00a0 (Note that this does not mean all poses are possible; the robot must always operate within its workspace.)\u00a0 For a simpler Cartesian 3P robot (like a 3D printer), it is possible to control x\/y\/z position, but not orientation, because such a robot cannot rotate its end effector.\u00a0 A 2R planar robot can control x\/y position only, due to having only 2 DoF, but a 3R planar robot can control both x\/y position and yaw orientation (angle around z) because it has 3 DoF.\u00a0 For most robots, the number of degrees of freedom corresponds to the number of controllable pose variables.<\/p>\n<p>As seen above, the inverse kinematics can be solved either algebraically or numerically in order to simulate the robot&#8217;s motion.\u00a0 If an algebraic solution is possible, this is the more accurate method.\u00a0 If the solution cannot be found algebraically, the Jacobian can be used to solve the joint positions numerically.\u00a0 This is computationally longer and less accurate, but it is a much easier method for solving complicated robots if done in silico (computer program) rather than by hand.\u00a0 The subsections below show how to solve inverse kinematics for a PR robot both algebraically and by hand, and how simulate the robot in MATLAB both ways.<\/p>\n<h2>Algebraic Solutions<\/h2>\n<p>An algebraic solution is one in which unknown variables can be solved for manually, and expressions for each unknown variable can be found independent of the others.\u00a0 This method is typically used for simple robots with three or fewer DoF.\u00a0 Examples of algebraic solutions for inverse kinematics are shown above in <a href=\"#ikexamples\">Part 1 of this chapter<\/a>.<\/p>\n<p>For this example, we will consider a simple PR robot: one prismatic joint and one revolute joint, the first one in <a href=\"https:\/\/youtu.be\/uB2gGXGhvx4\" rel=\"noopener\">PR Robot Singularities<\/a> video above.<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-35 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-300x250.jpg\" alt=\"Planar PR robot\" width=\"300\" height=\"250\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-300x250.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-1024x855.jpg 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-768x641.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-65x54.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-225x188.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1-350x292.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR1.jpg 1442w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.5: PR Planar Robot<\/figcaption><\/figure>\n<p>This robot operates in the YZ plane, where Z points up and Y points to the right.\u00a0 We can write the forward kinematics as follows:<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-36\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-300x179.jpg\" alt=\"PR Forward Kinematics Equations\" width=\"550\" height=\"329\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-300x179.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-768x459.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-65x39.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-225x134.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK-350x209.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_FK.jpg 860w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.6: PR Robot Forward Kinematics Equations<\/figcaption><\/figure>\n<p>Then we can rearrange these equations to solve for the inverse kinematics algebraically:<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-37\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-300x186.jpg\" alt=\"PR algebraic solution IK\" width=\"600\" height=\"371\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-300x186.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-768x475.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-65x40.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-225x139.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1-350x217.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_alg-1.jpg 960w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.7: Algebraic Inverse Kinematics Solution for PR Robot<\/figcaption><\/figure>\n<p>In order to simulate the robot with a computer program, the following steps are required, and can be used as an outline for the code:<\/p>\n<ul>\n<li>Define knowns, constants, and desired end effector path (x\/y\/z\/roll\/pitch\/yaw, whatever is applicable)<\/li>\n<li>Preallocate arrays to store calculated values for the IK<\/li>\n<li>Begin a for loop to start calculations for each frame\n<ul>\n<li>Calculate the joint values (IK) using the algebraic equations derived<\/li>\n<li>Calculate the joint and tip locations in space using FK equations<\/li>\n<li>Define arrays of points to plot (matrices of x, y, and z points)<\/li>\n<li>Plot the robot<\/li>\n<\/ul>\n<\/li>\n<li>End the for loop<\/li>\n<\/ul>\n<p>An example code using the algebraic method to simulate the PR robot is shown below.\u00a0 This book software cannot read or attach .m files, so a downloadable version is not possible, but you may copy and paste from the textbox.<\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Example Algebraic Code for PR Robot Simulation<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p><span style=\"color: #339966;\"><code>%% PR manipulator simulation (Algebraic solution)<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% PR robot tracing path<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% Robot operates in YZ plane<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% Elissa Ledoux ENGR 4501 Spring 2025<\/code><\/span><\/p>\n<p><code>clc<\/code><br \/>\n<code>clear<\/code><br \/>\n<code>close all<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% define constants (arbitrary if not given)<\/code><\/span><br \/>\n<code>r = 0.5; % link lengths (m)<\/code><br \/>\n<code>nsteps = 50; % number of steps<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% define desired path for end effector (m)<\/code><\/span><br \/>\n<code>ystart = 0.5; <\/code><br \/>\n<code>ystop = -0.48;<\/code><br \/>\n<code>pdesy = linspace(ystart,ystop,nsteps);<\/code><br \/>\n<code>pdesz = .7 - (pdesy-0.1).^2; % path option 1<br \/>\n<span style=\"color: #339966;\">% pdesz = 0.5 + 0.2*sin(pdesy*10*pi); % path option 2<\/span><\/code><br \/>\n<code>pdes = [pdesy;pdesz]; % waypoints (m)<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% preallocate arrays<\/code><\/span><br \/>\n<code>tip = zeros(2,nsteps); % actual tip path (y and z)<\/code><br \/>\n<code>d = zeros(nsteps,1); % prismatic joint<\/code><br \/>\n<code>th = zeros(nsteps,1); % revolute joint<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% calculate kinematics<\/code><\/span><br \/>\n<code><span style=\"color: #0000ff;\">for<\/span> i = 1:nsteps<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% solve algebraically<\/code><\/span><br \/>\n<code>th(i) = acos(pdesy(i)\/r);<\/code><br \/>\n<code>d(i) = pdesz(i) - r*sin(th(i));<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% check solution<\/code><\/span><br \/>\n<code>y = r*cos(th(i));<\/code><br \/>\n<code>z = d(i) + r*sin(th(i));<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% calculate points to plot (location of each joint)<\/code><\/span><br \/>\n<code>tip(:,i) = [y;z];<\/code><br \/>\n<code>j1y = 0; j1z = 0; % joint 1<\/code><br \/>\n<code>j2y = 0; j2z = d(i); % joint 2<\/code><br \/>\n<code>jey = r*cos(th(i)); jez = d(i)+r*sin(th(i)); % end effector<\/code><br \/>\n<code>Y = [j1y, j2y, jey];<\/code><br \/>\n<code>Z = [j1z, j2z, jez];<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% plot robot<\/code><\/span><br \/>\n<code>figure(1)<\/code><br \/>\n<code>clf<\/code><br \/>\n<code>hold on<\/code><br \/>\n<code>plot([j1y,j2y],[j1z,j2z],'k','LineWidth',3)<\/code><br \/>\n<code>plot([j2y,jey],[j2z,jez],'r','LineWidth',3)<\/code><br \/>\n<code>plot(j1y,j1z,'ksq','MarkerSize',10,'MarkerFaceColor','k')<\/code><br \/>\n<code>plot(j2y,j2z,'ro','MarkerSize',10,'MarkerFaceColor','r')<\/code><br \/>\n<code>plot(jey,jez,'b*','MarkerSize',10)<\/code><br \/>\n<code>plot(tip(1,1:i),tip(2,1:i),'b')<\/code><br \/>\n<code>xlim([-1 1]); xlabel('Y (m)')<\/code><br \/>\n<code>ylim([-.5 1.5]); ylabel('Z (m)')<\/code><br \/>\n<code>axis square<\/code><br \/>\n<code>title('PR Planar Manipulator')<\/code><\/p>\n<p><span style=\"color: #0000ff;\"><code>end<\/code><\/span><\/p>\n<\/div>\n<\/div>\n<h2><a id=\"numerical\" href=\"\"><\/a>Numerical Solutions<\/h2>\n<p>A numerical solution is one in which unknown variables cannot be solved for manually, and rather are done using the guess-and-check method known as &#8220;Newton&#8217;s method&#8221; or the &#8220;Newton-Rhapson method.&#8221;\u00a0 This method is typically used for complicated robots with three or more DoF.\u00a0 A numerical solution is done using the robot&#8217;s Jacobian to iteratively guide guesses for the joint values to until they converge, resulting in a solution for the IK.\u00a0 <strong>IF YOU ARE NEW TO NEWTON&#8217;S METHOD, STUDY <a href=\"#newton\">SECTION 5 BELOW<\/a> BEFORE PROCEEDING SO YOU WILL NOT BE UTTERLY LOST.<\/strong><\/p>\n<p>For this example, we will consider a the same RP robot as before, with the same forward kinematics, and solve for the inverse kinematics numerically using a while loop (guess-and-check while error is greater than a tolerance value and the solution for joint positions converges).\u00a0 This requires deriving the Jacobian of the robot by hand and choosing an initial guess for the joint values before using a computer program to solve the system numerically.\u00a0 The velocity, Jacobian, and guess iteration formulas for this PR robot are shown in the figure below:<\/p>\n<figure id=\"attachment_38\" aria-describedby=\"caption-attachment-38\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-38\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-300x225.jpg\" alt=\"PR robot velocity and Jacobian\" width=\"600\" height=\"450\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-300x225.jpg 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-768x576.jpg 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-65x49.jpg 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-225x169.jpg 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num-350x263.jpg 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/PR_num.jpg 960w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption id=\"caption-attachment-38\" class=\"wp-caption-text\">Figure 4.8: Jacobian and Velocity Kinematics Equations of the PR Robot<\/figcaption><\/figure>\n<p><span style=\"text-align: initial; font-size: 1em;\">In order to simulate the robot with a computer program, the following process is required (similarly to the algebraic solution but with additional steps), and can be used as an outline for the code:<\/span><\/p>\n<ul>\n<li>Define knowns, constants, and desired end effector path (x\/y\/z\/roll\/pitch\/yaw, whatever is applicable)<\/li>\n<li>Preallocate arrays to store calculated values for the IK<\/li>\n<li>Choose initial guesses for the joint values (these <span style=\"text-decoration: underline;\">must<\/span> be reasonably accurate or the program will get stuck in an infinite loop and never solve.\u00a0 I.e. ensure $\\theta$ is in the correct quadrant and $d$ is on the correct order of magnitude)<\/li>\n<li>Begin a for loop to start calculations for each frame\n<ul>\n<li>Find the current tip position\u00a0<em>F<\/em> using FK based on the initial guesses<\/li>\n<li>Calculate the magnitude of position error<\/li>\n<li>Start a while loop to iterate guesses\n<ul>\n<li>Calculate the Jacobian using the current guesses<\/li>\n<li>Calculate new joint values using $\\theta_{new} = \\theta{old} &#8211; J^{-1}F$<\/li>\n<li>Find the new tip position using FK based on the new guesses<\/li>\n<li>Calculate the magnitude of position error<\/li>\n<\/ul>\n<\/li>\n<li>Exit the while loop once guesses are close enough (error within tolerance)<\/li>\n<li>Calculate the joint and tip locations in space using FK equations with the correct guesses<\/li>\n<li>Define arrays of points to plot (matrices of x, y, and z points)<\/li>\n<li>Plot the robot<\/li>\n<\/ul>\n<\/li>\n<li>End the for loop<\/li>\n<\/ul>\n<p>An example code using the numerical method to simulate the PR robot is shown below.\u00a0 This book software cannot read or attach .m files, so a downloadable version is not possible, but you may copy and paste from the textbox.<\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Example Numerical Code for PR Robot Simulation<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p><span style=\"color: #339966;\"><code>%% PR manipulator simulation (Numerical Solution)<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% PR robot tracing path<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% Robot operates in YZ plane<\/code><\/span><br \/>\n<span style=\"color: #339966;\"><code>% Elissa Ledoux ENGR 4501 Spring 2025<\/code><\/span><\/p>\n<p><code>clc<\/code><br \/>\n<code>clear<\/code><br \/>\n<code>close all<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% define constants (arbitrary if not given)<\/code><\/span><br \/>\n<code>r = 0.5; % link lengths (m)<\/code><br \/>\n<code>nsteps = 50; % number of steps<\/code><br \/>\n<code>dt = 0.1; % timestep<\/code><br \/>\n<code>vee = 1; % end effector velocity (m\/s)<\/code><br \/>\n<code>tol = 10^(-3); % accuracy tolerance (m)<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% define desired path for end effector (m)<\/code><\/span><br \/>\n<code>ystart = 0.5; <\/code><br \/>\n<code>ystop = -0.48;<\/code><br \/>\n<code>pdesy = linspace(ystart,ystop,nsteps);<\/code><br \/>\n<code>pdesz = .7 - (pdesy-0.1).^2; % path option 1<\/code><br \/>\n<code>% pdesz = 0.5 + 0.2*sin(pdesy*10*pi); % path option 2<\/code><br \/>\n<code>pdes = [pdesy;pdesz]; % waypoints (m)<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% preallocate arrays<\/code><\/span><br \/>\n<code>tip = zeros(2,nsteps); % actual tip path (y and z)<\/code><br \/>\n<code>d = zeros(nsteps,1); % prismatic joint<\/code><br \/>\n<code>th = zeros(nsteps,1); % revolute joint<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% initial guesses (joint positions)<\/code><\/span><br \/>\n<code>d_guess = 0.2; d(1) = d_guess;<\/code><br \/>\n<code>th_guess = pi\/10; th(1) = th_guess;<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% calculate kinematics<\/code><\/span><br \/>\n<code><span style=\"color: #0000ff;\">for<\/span> i = 1:nsteps<\/code><br \/>\n<code>c = 0; % counter<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find current point using FK (use basic, DH, or product of exp method)<\/code><\/span><br \/>\n<code>y = r*cos(th(i));<\/code><br \/>\n<code>z = d(i) + r*sin(th(i));<\/code><br \/>\n<code>pcur = [y;z];<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find error<\/code><\/span><br \/>\n<code>errvec = pdes(:,i)-pcur;<\/code><br \/>\n<code>err = norm(errvec);<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% solve numerically (guess-and-check Newton's method)<\/code><\/span><br \/>\n<code><span style=\"color: #0000ff;\">while<\/span> err &gt; tol <\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find Jacobian (2D) (use basic or formula method)<\/code><\/span><br \/>\n<code>J = [0, -r*sin(th_guess); ...<\/code><br \/>\n<code>1, r*cos(th_guess)];<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find velocities of end effector and joints<\/code><\/span><br \/>\n<code>xdot = vee*errvec;<\/code><br \/>\n<code>qdot = J\\xdot;<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% calculate new joint positions<\/code><\/span><br \/>\n<code>q = [d_guess; th_guess]+qdot*dt;<\/code><br \/>\n<code>d_guess = q(1); th_guess = q(2);<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find current point using FK (use basic, DH, or product of exp)<\/code><\/span><br \/>\n<code>y = r*cos(th_guess);<\/code><br \/>\n<code>z = d_guess + r*sin(th_guess);<\/code><br \/>\n<code>pcur = [y;z];<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% find error<\/code><\/span><br \/>\n<code>errvec = pdes(:,i)-pcur;<\/code><br \/>\n<code>err = norm(errvec);<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% update counter<\/code><\/span><br \/>\n<code>c = c+1;<\/code><br \/>\n<span style=\"color: #0000ff;\"><code>end<\/code><\/span><\/p>\n<p><span style=\"color: #339966;\"><code>% save correct joint positions<\/code><\/span><br \/>\n<code>d(i) = d_guess;<\/code><br \/>\n<code>th(i) = th_guess;<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% calculate points to plot (location of each joint)<\/code><\/span><br \/>\n<code>tip(:,i) = [y;z];<\/code><br \/>\n<code>j1y = 0; j1z = 0; % joint 1<\/code><br \/>\n<code>j2y = 0; j2z = d(i); % joint 2<\/code><br \/>\n<code>jey = r*cos(th(i)); jez = d(i)+r*sin(th(i)); % end effector<\/code><br \/>\n<code>Y = [j1y, j2y, jey];<\/code><br \/>\n<code>Z = [j1z, j2z, jez];<\/code><\/p>\n<p><span style=\"color: #339966;\"><code>% plot robot<\/code><\/span><br \/>\n<code>figure(1)<\/code><br \/>\n<code>clf<\/code><br \/>\n<code>hold on<\/code><br \/>\n<code>plot([j1y,j2y],[j1z,j2z],'k','LineWidth',3)<\/code><br \/>\n<code>plot([j2y,jey],[j2z,jez],'r','LineWidth',3)<\/code><br \/>\n<code>plot(j1y,j1z,'ksq','MarkerSize',10,'MarkerFaceColor','k')<\/code><br \/>\n<code>plot(j2y,j2z,'ro','MarkerSize',10,'MarkerFaceColor','r')<\/code><br \/>\n<code>plot(jey,jez,'b*','MarkerSize',10)<\/code><br \/>\n<code>plot(tip(1,1:i),tip(2,1:i),'b')<\/code><br \/>\n<code>xlim([-1 1]); xlabel('Y (m)')<\/code><br \/>\n<code>ylim([-.5 1.5]); ylabel('Z (m)')<\/code><br \/>\n<code>axis square<\/code><br \/>\n<code>title('PR Planar Manipulator')<\/code><\/p>\n<p><span style=\"color: #0000ff;\"><code>end<\/code><\/span><\/p>\n<\/div>\n<\/div>\n<p>A more detailed and downloadable outline for code logic including pose control (position and orientation both) is available here: <a href=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/Pose-Control-Logic.pdf\" rel=\"noopener\">Pose Control Logic<\/a><\/p>\n<h1><a id=\"newton\" href=\"\"><\/a>5) Review of Newton&#8217;s Method for Numerical Solutions<\/h1>\n<p>Newton&#8217;s method, or the Newton-Rhapson method, is a way to solve equations numerically, by finding roots or unknowns of a function or system of equations using a guess-and-check procedure.\u00a0 In advanced kinematics courses, it is used to solve and simulate mechanisms such as closed-chain or hybrid-chain linkages using vector loop equations.\u00a0 In robotics, Newton&#8217;s method can also be used to simulate both parallel and serial robots using forward and inverse kinematics.<\/p>\n<p>The basic process is:<\/p>\n<ol>\n<li>Make an initial guess<em>G <\/em>of values for the unknown variables<\/li>\n<li>Calculate the value of the function <em>F <\/em>using the guess\u00a0<em>G<\/em><\/li>\n<li>Check if the function value <em>F<\/em>\u00a0nears zero.\u00a0 If so, stop.\u00a0 The guess is correct.\u00a0 If not, continue to step 4.<\/li>\n<li>Calculate the derivative (Jacobian) <em>J<\/em> of the function and plug in the guess values.<\/li>\n<li>Calculate a new guess <em>G <\/em>using the formula $G = G &#8211; J^{-1}F$<\/li>\n<li>Repeat steps 2-5 until solved<\/li>\n<\/ol>\n<p>An explanation of the theory as well as a simple example using a scalar equation and single unknown variable is in this video: <a href=\"https:\/\/youtu.be\/RPtpDQHgvk0\">Newton&#8217;s Method Explained + Example<\/a>.<\/p>\n<p>The process above can be followed to solve the equation using a computer program rather than by hand.\u00a0 A video tutorial on how to do this is here: <a href=\"https:\/\/youtu.be\/1srF-6GLRMU\">Programming Newton&#8217;s Method in MATLAB<\/a>.<\/p>\n<p>If more than one variable must be solved for, such as multiple unknown joint values of a robot, matrices must be used instead of scalars.\u00a0 An explanation of how to set up matrices for a system of two equations and two unknowns for a parallel closed-chain mechanism is in this video: <a href=\"https:\/\/youtu.be\/1d7bTylFuBM\">Four Bar Linkage Solution Newton&#8217;s Method.<\/a><\/p>\n<p>This completes the review, and you are now ready to return to <a href=\"#numerical\">Part 4 of this chapter<\/a> to solve and simulate a robot in Matlab numerically.<\/p>\n","protected":false},"author":1,"menu_order":4,"template":"","meta":{"pb_show_title":"","pb_short_title":"Ch. 4: Inverse Kinematics and Jacobian","pb_subtitle":"","pb_authors":["eledoux"],"pb_section_license":""},"chapter-type":[],"contributor":[62],"license":[],"class_list":["post-45","chapter","type-chapter","status-publish","hentry","contributor-eledoux"],"part":18,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/45\/revisions\/46"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/parts\/18"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/45\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapter-type?post=45"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/contributor?post=45"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/license?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}