Eric Scott Barrhttps://eb2.co/Recent content on Eric Scott BarrHugo -- gohugo.ioen-us© 2017 Eric Scott BarrThu, 17 Dec 2020 04:46:16 -0600- C++ Tips and Tricks: Swap-ishhttps://eb2.co/blog/2020/12/c-tips-and-tricks-swap-ish/Thu, 17 Dec 2020 04:46:16 -0600https://eb2.co/blog/2020/12/c-tips-and-tricks-swap-ish/Swapping values in C++ is simple enough with the std::swap standard algorithm. But what if an operation logically requires some transformation on one or both values prior to swapping? Is there some idiomatic solution to combining a swap with transformations? Here’s a quick tip to show how to achieve this goal with a little inspiration from other languages.
The Standard Approach Given two variables of the same type, swapping and then performing some transforming operation like negating one of the values looks like the following:
- Trigonometric Integralshttps://eb2.co/blog/2016/01/trigonometric-integrals/Thu, 21 Jan 2016 08:11:43 +0000https://eb2.co/blog/2016/01/trigonometric-integrals/<p>This week I started back to my journey in mathematics, this time tackling Calculus II. Starting out the week was the section I ended with in Calc I, integration by parts. No sweat! However, the second section for the week was Trigonometric Integrals. I’m not certain what I was expecting exactly going into the section, however, after working a few problems I realized something very interesting: I really hadn’t learned any new skills, what I had learned was a way to leverage skills I already had to solve problems that were previously unapproachable. Let me demonstrate with finding a solution for the following integration problem:</p>
<link rel="stylesheet" href="https://eb2.co/katex/katex.min.css" />
<script defer src="https://eb2.co/katex/katex.min.js"></script>
<script defer src="https://eb2.co/katex/contrib/auto-render.min.js" onload="renderMathInElement(document.body,{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"},{"display":true,"left":"\\[","right":"\\]"}]});"></script><span>
\[\int \frac{\sin \phi}{\cos^{3}\phi}\ d\phi \]
</span>
<h3 id="what-am-i-doing-here">What am I doing here?</h3>
<p>I’ve learned that the asking and answering of this question for myself is critical to solving problems. In this case, I’m trying to solve an integration problem but, truth be told, I know of know way to integrate this problem as it is. It’s not in a basic form. The only option in this circumstance is to manipulate the equation until it resembles a basic form that can be solved. So if I had to take a wild guess as to what I’m really doing here, it would be that I’m going to be manipulating this equation to get it into a basic form.</p>
<h3 id="manipulating-to-integrate">Manipulating to integrate</h3>
<p>To this point I’ve learned a few ways to manipulate problems:</p>
<ol>
<li><strong>Algebraic</strong> - Perhaps the simplest manipulation, manipulating the problem algebraically to simplify it into a basic form that can be solved.</li>
<li><strong>U-Substitution</strong> - Useful for solving integrals that are composed of a function <em>and its derivative</em>.</li>
<li><strong>Integration by Parts</strong> - Leveraging a proven relationship to break apart an integral into a function and a, hopefully, simpler integral to solve.</li>
</ol>
<p>Note that at times, these manipulation strategies can be combined in order to achieve a solution. However, in the case of the problem I am trying to solve, none of these situations directly apply.</p>
<p>It should come as no surprise then, that all there is to solving trigonometric integrals is leveraging trigonometric manipulations to get an equation into a basic, solvable, form.</p>
- Areas Between Curves: Thinking Outside the Vertical Boxhttps://eb2.co/blog/2015/12/areas-between-curves-thinking-outside-the-vertical-box/Fri, 04 Dec 2015 08:11:43 +0000https://eb2.co/blog/2015/12/areas-between-curves-thinking-outside-the-vertical-box/When learning a number of new math concepts in a short period of time, it can be tempting to just remember the processes and apply them unconditionally, and it often works. However, by not trying to understand a problem first and going straight for the process, we can actually make our lives much more difficult than is necessary. Lets take a look at this by considering the problem of finding the area between $ x = y^2 - 4y $ and $ x = 2y-y^2 $.
- The volume of the intersection of two similar pipeshttps://eb2.co/blog/2015/11/the-volume-of-the-intersection-of-two-similar-pipes/Sun, 29 Nov 2015 21:12:09 +0000https://eb2.co/blog/2015/11/the-volume-of-the-intersection-of-two-similar-pipes/Thanksgiving break is here and after the feasting, when the food weighs heavy and the mind drifts into that hazy place between sleep and awake thanks to loads of carbs and tryptophan, we might find ourselves wondering what the volume is of the space created by two intersecting pipes. At least, my calculus professor seems to think that would be a good quandary to mull over. In this article we will use Thanksgiving leftovers to help visualize the space created by two intersecting pipes and then try to determine the volume of that space; first via approximating and then by getting serious with the tools we’ve learned in first year calculus.
- U-Substitution? U Gotta Be Kiddinghttps://eb2.co/blog/2015/11/u-substitution-u-gotta-be-kidding/Wed, 25 Nov 2015 04:24:27 +0000https://eb2.co/blog/2015/11/u-substitution-u-gotta-be-kidding/This week in class we’ve been learning the interesting things for which area’s under a curve provide an answer. And whats finding a definite integral but taking a couple antiderivatives and finding their difference? Nothing to it, right? Wrong!
Let me explain the situation. Currently, I’ve spent most of a semester working with the differential branch of calculus. I have a fair understanding of what derivatives are, what they represent. Having spent the first weeks of the semester using limits to find the slopes of tangent lines, I certainly have an appreciation for how powerful they are.
- Reference Angles and the Fundamental Identityhttps://eb2.co/blog/2015/06/reference-angles-and-the-fundamental-identity/Sat, 13 Jun 2015 02:10:45 +0000https://eb2.co/blog/2015/06/reference-angles-and-the-fundamental-identity/In the previous article in the series on trigonometry, the focus was on solving right triangles using their unique properties. But what about angles that don’t fit nicely within quadrant I of the cartesian coordinate plane? This article will demonstrate how to solve these types of angles/triangles using reference angles. Finally, it will wrap up by explaining an interesting relationship between sine and cosine, also known as the Fundamental Identiy.
- Trigonometry and Right Angleshttps://eb2.co/blog/2015/06/trigonometry-and-right-angles/Fri, 12 Jun 2015 02:10:45 +0000https://eb2.co/blog/2015/06/trigonometry-and-right-angles/Using all the tricks in the proverbial math bag that have been gathered in the course of this series on trigonometry, it is possible to determine what the measures of the sides and angles of a right triangle trigonometrically; without measuring them. This article will demonstrate how to solve a triangle but first it will start with a question. Given a right triangle, where one angle is 90° and another angle $ \alpha $, which must be $ 0° \le \alpha \le 90° $: what is the value of $ \alpha $ if the $ \text{sin}\ \alpha = \frac{\sqrt{2}}{2} $?
- Trigonometric Functionshttps://eb2.co/blog/2015/06/trigonometric-functions/Thu, 11 Jun 2015 06:10:45 +0000https://eb2.co/blog/2015/06/trigonometric-functions/At the heart of trigonometry lies the study of the relationship between the angles of a triangle and the length of its sides. There exists 6 such relationships, known as the trigonometric functions. This article in the series on trigonometry aims to define the trigonometric functions as a set of ratios and show how they can be derived from certain common angles.
To begin consider an angle $ \alpha $ in standard position and a terminal side forming an angle between 0° and 90°, with a point $ \text{(x,y)} $ anywhere on the terminal side that is not the origin.
- Angular and Linear Velocitieshttps://eb2.co/blog/2015/06/angular-and-linear-velocities/Wed, 10 Jun 2015 22:10:45 +0000https://eb2.co/blog/2015/06/angular-and-linear-velocities/This article will look at objects that rotate around a circle and introduce two forms of velocity, which is the rate at which objects move in relation to time: angular and linear velocities. The initial article of this series on trigonometry defined an angle as one ray, the terminal side, rotating away from another ray, the initial side. In the second article, two points of those rays were fixed onto a unit circle.
- Radians, Arcs, and Everything Betweenhttps://eb2.co/blog/2015/06/radians-arcs-and-everything-between/Wed, 10 Jun 2015 02:10:45 +0000https://eb2.co/blog/2015/06/radians-arcs-and-everything-between/In everyday life when most people think of angles and their measurements, they think of a measurement in degrees. However, as previously mentioned, this unit of measurement is based on a crude likening of rotations around a point to the rotation of the earth around the sun. This results in some rather complicated formulas when working with degrees. For this reason, another type of measurement was divised, one that is based in mathmatics.
- Angles and Their Measurementshttps://eb2.co/blog/2015/06/angles-and-their-measurements/Mon, 08 Jun 2015 02:10:45 +0000https://eb2.co/blog/2015/06/angles-and-their-measurements/What are angles? How are they measured? Answering these questions is the focus of this article, part of a series on trigonometry. This article will identify all the constituants of an angle, describe several special angles, and show how angles have been measured for thousands of years.
The first step to understanding angles, is understanding what a ray is. Rays are defined by a point on a fixed line, and all the points to one side, or the other, of that point.
- Driving Boost.Test with CMakehttps://eb2.co/blog/2015/06/driving-boost.test-with-cmake/Tue, 02 Jun 2015 02:10:45 +0000https://eb2.co/blog/2015/06/driving-boost.test-with-cmake/Boost.Test is one of the more popular C++ based test frameworks on the market. With it being a boost library, chances are its already installed in the local environment, or can be easily built. This article doesn’t aim to show how to use Boost.Test. Rather, it shows how to incorporate building and running those tests with CMake, one of the most popular build systems for C++ projects. This article assumes that a CMake based project already exists.
- C++14 and SDL2: Managing Resourceshttps://eb2.co/blog/2014/04/c-14-and-sdl2-managing-resources/Thu, 17 Apr 2014 04:39:34 +0000https://eb2.co/blog/2014/04/c-14-and-sdl2-managing-resources/Update: The final solution in this article has been updated based on feedback from nanofortnight on Hacker News. This change, while not solving the complexity of what it means to work with C++ templates, does help significantly with the readability of this solution.
Update 2: Added a final example that shows how the general make_resource helper can be used to simplify writing higher level C++ abstractions around C libraries
Update 3: In order to offer proper RAII semantics the make_resource function now throws if the resource fails to create.
- Sphinx and CMake: Beautiful Documentation For C++ Projectshttps://eb2.co/blog/2012/03/sphinx-and-cmake-beautiful-documentation-for-c-projects/Tue, 13 Mar 2012 00:00:00 +0000https://eb2.co/blog/2012/03/sphinx-and-cmake-beautiful-documentation-for-c-projects/Let’s face it, documentation for (most) developers is boring and more often than not this is reflected in the quality of a project’s documentation. This is often a barrier that prevents adoption of otherwise well crafted projects in wide-spread production use. In this article we’ll take a look at how to integrate a documentation generator called Sphinx into an existing CMake based project for documentation that is regenerated each time you build the source.
- Building Boost.Python for Python 3.2https://eb2.co/blog/2012/03/building-boost.python-for-python-3.2/Mon, 05 Mar 2012 00:00:00 +0000https://eb2.co/blog/2012/03/building-boost.python-for-python-3.2/Boost.Python is an excellent tool for exposing C++ code to Python. Building Boost with support for the latest version of Python is not that difficult but as most unix systems ship with Python 2.7 or earlier the default options are generally not sufficient.
To start out, make sure that you have the latest version of Python installed. On Ubuntu or debian based environments this is as simple as running the following command.
- Installing Jenkins on Ubuntu Serverhttps://eb2.co/blog/2012/03/installing-jenkins-on-ubuntu-server/Sun, 04 Mar 2012 00:00:00 +0000https://eb2.co/blog/2012/03/installing-jenkins-on-ubuntu-server/Jenkins is an excellent platform for managing automated builds and getting started on Ubuntu Server is a snap. This guide covers the setup of Jenkins as well as how to use the default Ubuntu Apache web-server installation as a front-end to make URL’s nicer.
Installing Jenkins Installing Jenkins itself is pretty straightforward using default package system:
sudo apt-get install jenkins After the installation completes you can access the Jenkins installation at http://SERVER_IP:8080/