Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A block of mass m slides along a horizontal surface lubricated with a thick oil

ID: 3750509 • Letter: A

Question

A block of mass m slides along a horizontal surface lubricated with a thick oil which provides a drag force proportional to u2/3, given by 1/3 (Note that this is proportional to v2/3, because v can be written as a magnitude times the unit vector v, and thus Fdrag o 2/3) (a) Use a system of units such that B/m 1, and write a C++ code using the Euler algorithm where the user inputs an initial velocity vo, and determine v and as a function of time Are there any points or values of the time step where you see everything break down? Do you ever see any unreasonable results? (b) Determine the maximum distance the block can slide for initial velocities (in this odd system of units) of 1, 2, 3, 5, and 10. For each vo, use time steps T 0.1 and T 0.01, and compare the maximum distances. Use the difference in the results for the two time steps as your "error."

Explanation / Answer

a)

/* C++ Program to find approximation

   of a ordinary differential equation

   using euler method.*/

#include <iostream>

using namespace std;

  

// Consider a differential equation

// dy/dx=(x + y + xy)

float func(float x, float y)

{

    return (x + y + x * y);

}

  

// Function for Euler formula

void euler(float x0, float y, float h, float x)

{

    float temp = -0;

  

    // Iterating till the point at which we

    // need approximation

    while (x0 < x) {

        temp = y;

        y = y + h * func(x0, y);

        x0 = x0 + h;

    }

  

    // Printing approximation

    cout << "Approximate solution at x = "

         << x << " is " << y << endl;

}

  

// Driver program

int main()

{

    // Initial Values

    float x0 = 0;

    float y0 = 1;

    float h = 0.025;

  

    // Value of x at which we need approximation

    float x = 0.1;

  

    euler(x0, y0, h, x);

    return 0;

}

The numerical solution gets worse and worse as we move further to the right. We might even be prompted to ask the question "What good is a solution that is this bad?" The answer is "Very little good at all!" So should we quit using this method? No! The reason our numerical solution is so inaccurate is because our step-size is so large. To improve the solution, shrink the step-size!

By the way, the reason I used such a large step size when we went through this problem is because we were working it by hand. When we move on to using the computer to do the work, we needn't be so afraid of using tiny step-sizes.

To illustrate that Euler's Method isn't always this terribly bad,here if you use a step size of h = 0.02: is fine

b)Adaptive stepsize methods that use a so-called 'embedded' error estimate include the Runge–Kutta–Fehlberg, Cash–Karp and Dormand–Prince methods. These methods are considered to be more computationally efficient, but have lower accuracy in their error estimates.

. The local error estimate can be used to decide how stepsize h should be modified to achieve the desired accuracy. For example, if a local tolerance of

tol

is allowed, we could let h evolve like:

h 0.9 × h × min ( max ( t o l | n + 1 ( 1 ) | , 0.3 ) , 2 )

The

0.9 is a safety factor to ensure success on the next try. The minimum and maximum are to prevent extreme changes from the previous stepsize. This should, in principle give an error of about

0.9 × t o l in the next try. If

| n + 1 ( 1 ) | < t o l

, we consider the step successful, and the error estimate is used to improve the solution:

y n + 1 ( 2 ) = y n + 1 ( 1 ) + n + 1 ( 1 )

This solution is actually third order accurate in the local scope (second order in the global scope), but since there is no error estimate for it, this doesn't help in reducing the number of steps. This technique is called Richardson extrapolation.

Beginning with an initial stepsize of h = b a

, this theory facilitates our controllable integration of the ODE from point

a to b, using an optimal number of steps given a local error tolerance. A drawback is that the step size may become prohibitively small, especially when using the low-order Euler method.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote