{"id":18966,"date":"2022-11-02T12:21:04","date_gmt":"2022-11-02T06:51:04","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/"},"modified":"2022-11-02T12:21:04","modified_gmt":"2022-11-02T06:51:04","slug":"solved-basic-example-of-how-to-do-numerical-integration-in-c","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/","title":{"rendered":"[Solved] Basic example of how to do numerical integration in C++"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-72162992\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"72162992\" data-parentid=\"72162294\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<h2>Numerical derivation and integration in code for physics, mapping, robotics, gaming, dead-reckoning, and controls<\/h2>\n<p><em>Pay attention to where I use the words &#8220;estimate&#8221; vs &#8220;measurement&#8221; below. The difference is important.<\/em><\/p>\n<ol>\n<li><strong>Measurements<\/strong> are direct readings from a sensor.\n<ol>\n<li>Ex: a GPS measures <em>position<\/em> (meters) directly, and a speedometer measures <em>speed<\/em> (m\/s) directly.<\/li>\n<\/ol>\n<\/li>\n<li><strong>Estimates<\/strong> are <em>calculated projections<\/em> you can obtain through integrating and derivating (deriving) measured values.<br \/>\nEx: you can <em>derive<\/em> position measurements (m) with respect to time to obtain speed or velocity (m\/s) <em>estimates<\/em>, and you can <em>integrate<\/em> speed or velocity measurements (m\/s) with respect to time to obtain position or displacement (m) <em>estimates<\/em>.<\/li>\n<li>Wait, aren&#8217;t <em>all<\/em> &#8220;measurements&#8221; actually just &#8220;estimates&#8221; at some fundamental level?\n<ol>\n<li>Yeah&#8211;pretty much! But, they are not necessarily produced through derivations or integrations with respect to time, so that is a bit different.<\/li>\n<li>Also note that technically, virtually nothing can truly be measured directly. All sensors get reduced down to a voltage or a current, and guess how you measure a current?&#8211;a voltage!&#8211;either as a voltage drop across a tiny resistance, or as a voltage induced through an inductive coil due to current flow. So, everything boils down to a voltage. Even devices which &#8220;measure speed directly&#8221; may be using pressure (pitot-static tube on airplane), doppler\/phase shift (radar or sonar), or looking at distance over time and then outputting speed. Fluid speed, or speed with respect to fluid such as air or water, can even be measured via a hot wire anemometer by measuring the current required to keep a hot wire at a fixed temperature, or by measuring the temperature change of the hot wire at a fixed current. And how is that temperature measured? Temperature is just a thermo-electrically-generated voltage, or a voltage drop across a diode or other resistance.<\/li>\n<li>As you can see, all of these &#8220;measurements&#8221; and &#8220;estimates&#8221;, at the low level, are intertwined. However, if a given device has been produced, tested, and calibrated to output a given &#8220;measurement&#8221;, then you can accept it as a &#8220;source of truth&#8221; for all practical purposes and call it a &#8220;measurement&#8221;. Then, anything you derive from that measurement, with respect to time or some other variable, you can consider an &#8220;estimate&#8221;. The irony of this is that if you calibrate your device and output derived or integrated estimates, someone else could then consider your output &#8220;estimates&#8221; as their input &#8220;measurements&#8221; in their system, in a sort of never-ending chain down the line. That&#8217;s being pedantic, however. Let&#8217;s just go with the simplified definitions I have above for the time being.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>The following table is true, for example. Read the 2nd line, for instance, as: &#8220;If you take the derivative of a velocity <em>measurement<\/em> with respect to time, you get an acceleration <em>estimate<\/em>, and if you take its integral, you get a position <em>estimate<\/em>.&#8221;<\/p>\n<pre class=\"lang-none prettyprint-override\"><code>Derivatives and integrals of position\n\nMeasurement, y              Derivative                  Integral\n                            Estimate (dy\/dt)            Estimate (dy*dt)\n-----------------------     -----------------------     -----------------------\nposition        [m]         velocity        [m\/s]       -               [m*s]\nvelocity        [m\/s]       acceleration    [m\/s^2]     position        [m]      \nacceleration    [m\/s^2]     jerk            [m\/s^3]     velocity        [m\/s]\njerk            [m\/s^3]     snap            [m\/s^4]     acceleration    [m\/s^2]\nsnap            [m\/s^4]     crackle         [m\/s^5]     jerk            [m\/s^3]\ncrackle         [m\/s^5]     pop             [m\/s^6]     snap            [m\/s^4]\npop             [m\/s^6]     -               [m\/s^7]     crackle         [m\/s^5]\n<\/code><\/pre>\n<p>For jerk, snap or jounce, crackle, and pop, see: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/Fourth,_fifth,_and_sixth_derivatives_of_position\">https:\/\/en.wikipedia.org\/wiki\/Fourth,_fifth,_and_sixth_derivatives_of_position<\/a>.<\/p>\n<h2>1. numerical derivation<\/h2>\n<p>Remember, derivation obtains the <em>slope<\/em> of the line, <code>dy\/dx<\/code>, on an x-y plot. The general form is <code>(y_new - y_old)\/(x_new - x_old)<\/code>.<\/p>\n<p>In order to obtain a <em>velocity estimate<\/em> from a system where you are obtaining repeated <em>position measurements<\/em> (ex: you are taking GPS readings periodically), you must numerically derivate your position measurements over time. Your <strong>y-axis is position<\/strong>, and your <strong>x-axis is time<\/strong>, so <code>dy\/dx<\/code> is simply <code>(position_new - position_old)\/(time_new - time_old)<\/code>. A units check shows this might be <code>meters\/sec<\/code>, which is indeed a unit for velocity.<\/p>\n<p>In code, that would look like this, for a system where you&#8217;re only measuring position in 1-dimension:<\/p>\n<pre class=\"lang-cpp prettyprint-override\"><code>double position_new_m = getPosition(); \/\/ m = meters\ndouble position_old_m;\n\/\/ `getNanoseconds()` should return a `uint64_t timestamp in nanoseconds, for\n\/\/ instance\ndouble time_new_sec = NS_TO_SEC((double)getNanoseconds());\ndouble time_old_sec;\n\nwhile (true)\n{\n    position_old_m = position_new_m;\n    position_new_m = getPosition();\n\n    time_old_sec = time_new_sec;\n    time_new_sec = NS_TO_SEC((double)getNanoseconds());\n\n    \/\/ Numerical derivation of position measurements over time to obtain\n    \/\/ velocity in meters per second (mps)\n    double velocity_mps = \n        (position_new_m - position_old_m)\/(time_new_sec - time_old_sec);\n}\n<\/code><\/pre>\n<h2>2. numerical integration<\/h2>\n<p>Numerical integration obtains the <em>area under the curve<\/em>, <code>dy*dx<\/code>, on an x-y plot. One of the best ways to do this is called <em>trapezoidal integration<\/em>, where you take the average <code>dy<\/code> reading and multiply by <code>dx<\/code>. This would look like this: <code>(y_old + y_new)\/2 * (x_new - x_old)<\/code>.<\/p>\n<p>In order to obtain a <em>position estimate<\/em> from a system where you are obtaining repeated <em>velocity measurements<\/em> (ex: you are trying to estimate distance traveled while only reading the speedometer on your car), you must numerically integrate your velocity measurements over time. Your <strong>y-axis is velocity<\/strong>, and your <strong>x-axis is time<\/strong>, so <code>(y_old + y_new)\/2 * (x_new - x_old)<\/code> is simply <code>velocity_old + velocity_new)\/2 * (time_new - time_old)<\/code>. A units check shows this might be <code>meters\/sec * sec = meters<\/code>, which is indeed a unit for distance.<\/p>\n<p>In code, that would look like this. Notice that the numerical integration obtains the distance traveled over that one tiny time interval. To obtain an estimate of the <em>total<\/em> distance traveled, you must sum all of the individual estimates of distance traveled.<\/p>\n<pre class=\"lang-cpp prettyprint-override\"><code>double velocity_new_mps = getVelocity(); \/\/ mps = meters per second\ndouble velocity_old_mps;\n\/\/ `getNanoseconds()` should return a `uint64_t timestamp in nanoseconds, for\n\/\/ instance\ndouble time_new_sec = NS_TO_SEC((double)getNanoseconds());\ndouble time_old_sec;\n\n\/\/ Total meters traveled\ndouble distance_traveled_m_total = 0;\n\nwhile (true)\n{\n    velocity_old_mps = velocity_new_mps;\n    velocity_new_mps = getVelocity();\n\n    time_old_sec = time_new_sec;\n    time_new_sec = NS_TO_SEC((double)getNanoseconds());\n\n    \/\/ Numerical integration of velocity measurements over time to obtain \n    \/\/ a distance estimate (in meters) over this time interval\n    double distance_traveled_m = \n        (velocity_old_mps + velocity_new_mps)\/2 * (time_new_sec - time_old_sec);\n    distance_traveled_m_total += distance_traveled_m;\n}\n<\/code><\/pre>\n<p>See also: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/en.wikipedia.org\/wiki\/Numerical_integration\">https:\/\/en.wikipedia.org\/wiki\/Numerical_integration<\/a>.<\/p>\n<h2>Going further:<\/h2>\n<h3>high-resolution timestamps<\/h3>\n<p>To do the above, you&#8217;ll need a good way to obtain timestamps. Here are various techniques I use:<\/p>\n<p>In C++, use my <code>uint64_t nanos()<\/code> function here.<\/p>\n<p>If using Linux in C <em>or<\/em> C++, use my <code>uint64_t nanos()<\/code> function which uses <code>clock_gettime()<\/code> here. Even better, I have wrapped it up into a nice <code>timinglib<\/code> library for Linux, in my <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/ElectricRCAircraftGuy\/eRCaGuy_hello_world\">eRCaGuy_hello_world<\/a> repo here:<\/p>\n<ol>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/ElectricRCAircraftGuy\/eRCaGuy_hello_world\/blob\/master\/c\/timinglib.h\">timinglib.h<\/a><\/li>\n<li><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/ElectricRCAircraftGuy\/eRCaGuy_hello_world\/blob\/master\/c\/timinglib.c\">timinglib.c<\/a><\/li>\n<\/ol>\n<p>Here is the <code>NS_TO_SEC()<\/code> macro from timing.h:<\/p>\n<pre class=\"lang-cpp prettyprint-override\"><code>#define NS_PER_SEC (1000000000L)\n\/\/\/ Convert nanoseconds to seconds\n#define NS_TO_SEC(ns)   ((ns)\/NS_PER_SEC)\n<\/code><\/pre>\n<p>If using a microcontroller, you&#8217;ll need to read an incrementing periodic counter from a timer or counter register which you have configured to increment at a steady, fixed rate. Ex: on Arduino: use <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.arduino.cc\/en\/reference\/micros\"><code>micros()<\/code><\/a> to obtain a microsecond timestamp with 4-us resolution (by default, it can be changed). On STM32 or others, you&#8217;ll need to configure your own timer\/counter.<\/p>\n<h3>use <em>high<\/em> data sample rates<\/h3>\n<p>Taking data samples as fast as possible in a sample loop is a good idea, because then you can average many samples to achieve:<\/p>\n<ol>\n<li>Reduced noise: averaging many raw samples reduces noise from the sensor.<\/li>\n<li>Higher-resolution: averaging many raw samples actually adds bits of resolution in your measurement system. This is known as <em>oversampling.<\/em>\n<ol>\n<li>I write about it on my personal website here: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/www.electricrcaircraftguy.com\/2014\/05\/using-arduino-unos-built-in-16-bit-adc.html\">ElectricRCAircraftGuy.com: Using the Arduino Uno\u2019s built-in 10-bit to 16+-bit ADC (Analog to Digital Converter)<\/a>.<\/li>\n<li>And Atmel\/Microchip wrote about it in their white-paper here: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/ww1.microchip.com\/downloads\/en\/Appnotes\/doc8003.pdf\">Application Note AN8003: AVR121: Enhancing ADC resolution by oversampling<\/a>.<\/li>\n<li>Taking <code>4^n<\/code> samples increases your sample resolution by <code>n<\/code> bits of resolution. For example:\n<pre><code>4^0 = 1    sample  at 10-bits resolution --&gt; 1 10-bit sample\n4^1 = 4    samples at 10-bits resolution --&gt; 1 11-bit sample\n4^2 = 16   samples at 10-bits resolution --&gt; 1 12-bit sample\n4^3 = 64   samples at 10-bits resolution --&gt; 1 13-bit sample\n4^4 = 256  samples at 10-bits resolution --&gt; 1 14-bit sample\n4^5 = 1024 samples at 10-bits resolution --&gt; 1 15-bit sample\n4^6 = 4096 samples at 10-bits resolution --&gt; 1 16-bit sample\n<\/code><\/pre>\n<p>See: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\"><img decoding=\"async\" src=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\" alt=\"\"><\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>So, sampling at <em>high sample rates<\/em> is good. You can do basic filtering on these samples.<\/p>\n<p>If you process raw samples at a high rate, doing <em>numerical derivation<\/em> on high-sample-rate raw samples will end up derivating a lot of <em>noise<\/em>, which produces noisy derivative estimates. This isn&#8217;t great. It&#8217;s better to do the derivation on filtered samples: ex: the average of 100 or 1000 rapid samples. Doing <em>numerical integration<\/em> on high-sample-rate raw samples, however, is fine, because as Edgar Bonet says, &#8220;when integrating, the more samples you get, the better the noise averages out.&#8221; This goes along with my notes above.<\/p>\n<p>Just using the filtered samples for both numerical integration and numerical derivation, however, is just fine.<\/p>\n<h3>use <em>reasonable<\/em> control loop rates<\/h3>\n<p>Control loop rates should not be too fast. The higher the <em>sample rates<\/em>, the better, because you can filter them to reduce noise. The higher the <em>control loop rate<\/em>, however, <em>not<\/em> necessarily the better, because there is a sweet spot in control loop rates. If your control loop rate is too slow, the system will have a slow frequency response and won&#8217;t respond to the environment fast enough, and if the control loop rate is too fast, it ends up just responding to sample <em>noise<\/em> instead of to real changes in the measured data.<\/p>\n<p>Therefore, even if you have a <em>sample rate<\/em> of 1 kHz, for instance, to oversample and filter the data, <em>control loops<\/em> that fast are not needed, as the noise from readings of real sensors over very small time intervals will be too large. Use a control loop anywhere from <strong>10 Hz ~ 100 Hz<\/strong>, perhaps up to <strong>400+ Hz<\/strong> for simple systems with clean data. In some scenarios you can go faster, but <strong>50 Hz<\/strong> is very common in control systems. The more-complicated the system and\/or the more-noisy the sensor measurements, generally, the <em>slower<\/em> the control loop must be, down to about <strong>1~10 Hz<\/strong> or so. Self-driving cars, for instance, which are <em>very complicated<\/em>, frequently operate at <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/physicstoday.scitation.org\/doi\/10.1063\/PT.3.4256#:%7E:text=updated%20at%20roughly-,10%20Hz,-%2C%20at%20a%20range\">control loops of only 10 Hz<\/a>.<\/p>\n<h3>loop timing and multi-tasking<\/h3>\n<p>In order to accomplish the above, independent <em>measurement and filtering loops<\/em>, and <em>control loops<\/em>, you&#8217;ll need a means of performing precise and efficient loop timing and multi-tasking.<\/p>\n<p>If needing to do precise, repetitive loops <strong>in Linux in C or C++<\/strong>, use the <code>sleep_until_ns()<\/code> function from my <code>timinglib<\/code> above. I have a demo of my <code>sleep_until_us()<\/code> function in-use in Linux to obtain repetitive loops as fast as <code>1 KHz to 100 kHz<\/code> here.<\/p>\n<p>If using <strong>bare-metal (no operating system) on a microcontroller<\/strong> as your compute platform, use <em>timestamp-based cooperative multitasking<\/em> to perform your control loop and other loops such as measurements loops, as required. See my detailed answer here: How to do high-resolution, timestamp-based, non-blocking, single-threaded cooperative multi-tasking.<\/p>\n<h3>full, numerical integration and multi-tasking example<\/h3>\n<p><strong>I have an in-depth example of both <em>numerical integration<\/em> and cooperative multitasking on a bare-metal system using my <code>CREATE_TASK_TIMER()<\/code> macro in my <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/arduino.stackexchange.com\/a\/75937\/7727\">Full coulomb counter example in code<\/a>.<\/strong> That&#8217;s a great demo to study, in my opinion.<\/p>\n<h3>Kalman filters<\/h3>\n<p>For robust measurements, you&#8217;ll probably need a Kalman filter, perhaps an &#8220;unscented Kalman Filter,&#8221; or UKF, because apparently they are &#8220;unscented&#8221; because they &#8220;don&#8217;t stink.&#8221;<\/p>\n<h2>See also<\/h2>\n<ol>\n<li>My answer on Physics-based controls, and control systems: the many layers of control<\/li>\n<\/ol>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">5<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Basic example of how to do numerical integration in C++ <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Numerical derivation and integration in code for physics, mapping, robotics, gaming, dead-reckoning, and controls Pay attention to where I use the words &#8220;estimate&#8221; vs &#8220;measurement&#8221; below. The difference is important. Measurements are direct readings from a sensor. Ex: a GPS measures position (meters) directly, and a speedometer measures speed (m\/s) directly. Estimates are calculated &#8230; <a title=\"[Solved] Basic example of how to do numerical integration in C++\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\" aria-label=\"More on [Solved] Basic example of how to do numerical integration in C++\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,4420,1223,3946,357],"class_list":["post-18966","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-calculus","tag-game-development","tag-integral","tag-math"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Basic example of how to do numerical integration in C++ - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Basic example of how to do numerical integration in C++ - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Numerical derivation and integration in code for physics, mapping, robotics, gaming, dead-reckoning, and controls Pay attention to where I use the words &#8220;estimate&#8221; vs &#8220;measurement&#8221; below. The difference is important. Measurements are direct readings from a sensor. Ex: a GPS measures position (meters) directly, and a speedometer measures speed (m\/s) directly. Estimates are calculated ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-02T06:51:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Basic example of how to do numerical integration in C++\",\"datePublished\":\"2022-11-02T06:51:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\"},\"wordCount\":1560,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\",\"keywords\":[\"c++\",\"calculus\",\"game-development\",\"integral\",\"math\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\",\"name\":\"[Solved] Basic example of how to do numerical integration in C++ - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\",\"datePublished\":\"2022-11-02T06:51:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Basic example of how to do numerical integration in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Basic example of how to do numerical integration in C++ - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Basic example of how to do numerical integration in C++ - JassWeb","og_description":"[ad_1] Numerical derivation and integration in code for physics, mapping, robotics, gaming, dead-reckoning, and controls Pay attention to where I use the words &#8220;estimate&#8221; vs &#8220;measurement&#8221; below. The difference is important. Measurements are direct readings from a sensor. Ex: a GPS measures position (meters) directly, and a speedometer measures speed (m\/s) directly. Estimates are calculated ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/","og_site_name":"JassWeb","article_published_time":"2022-11-02T06:51:04+00:00","og_image":[{"url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG","type":"","width":"","height":""}],"author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Basic example of how to do numerical integration in C++","datePublished":"2022-11-02T06:51:04+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/"},"wordCount":1560,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG","keywords":["c++","calculus","game-development","integral","math"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/","url":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/","name":"[Solved] Basic example of how to do numerical integration in C++ - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage"},"image":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG","datePublished":"2022-11-02T06:51:04+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#primaryimage","url":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/uploads\/2022\/11\/Solved-Basic-example-of-how-to-do-numerical-integration-in.PNG"},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-basic-example-of-how-to-do-numerical-integration-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Basic example of how to do numerical integration in C++"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/18966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=18966"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/18966\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=18966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=18966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=18966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}