The following error message was received after running my code located at the end of the message:

terminate called after throwing an instance of 'std::out\_of\_range'
 what(): vector::\_M\_range\_check: \_\_n (which is 0) >= this->size() (which is 0)

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

I'm sorry for the length of the code. It appears that the error is coming from when I am calling the numerov function within the f function. If you are able to determine what the error is would you please let me know? Thank you!

```
#include <iostream>
#include <cmath>
#include <fstream>
#include <vector>

using namespace std;

int nx = 500, m = 10, ni = 10;
double x1 = 0, x2 = 1, h = (x2 - x1)/nx;
int nr, nl;
vector<double> ul, q, u;

//Method to achieve the evenly spaced Simpson rule
double simpson(vector <double> y, double h)
{
    int n = y.size() - 1;
    double s0 = 0, s1 = 0, s2 = 0;
    for (int i = 1; i < n; i += 2)
    {
        s0 += y.at(i);
        s1 += y.at(i-1);
        s2 += y.at(i+1);
    }
    double s = (s1 + 4*s0 + s2)/3;

//Add the last slice separately for an even n+1
if ((n+1)%2 == 0)
    return h*(s + (5*y.at(n) + 8*y.at(n-1) - y.at(n-2))/12);
else
    return h*2;
}

//Method to perform the Numerov integration
vector <double> numerov(int m, double h, double u0, double u1, double q)
{
    vector<double> u;
    u.push_back(u0);
    u.push_back(u1);
    double g = h*h/12;
    for (int i = 1; i < m+1; i++)
    {
        double c0 = 1 + g*q;
        double c1 = 2 - 10*g*q;
        double c2 = 1 + g*q;
        double d = g*(0);
        u.push_back((c1*u.at(i) - c0*u.at(i-1) + d)/c2);
    }
    return u;
}

//Method to provide the function for the root search
double f(double x)
{
    vector<double> w;
    vector<double> j = numerov(nx + 1, h, 0.0, 0.001, x);
    for (int i = 0; i < 0; i++)
    {
        w.push_back(j.at(i));
    }
    return w.at(0);
}

//Method to carry out the secant search
double secant(int n, double del, double x, double dx)
{
    int k = 0;
    double x1 = x + dx;
    while ((abs(dx) > del) && (k < n))
    {
        double d = f(x1) - f(x);
        double x2 = x1 - f(x1)*(x1 - x)/d;
        x = x1;
        x1 = x2;
        dx = x1 - x;
        k++;
    }
    if (k == n)
        cout << "Convergence not found after " << n << " iterations." <<                 endl;
    return x1;
}

int main()
{
    double del = 1e-6, e = 0, de = 0.1;

    //Find the eigenvalue via the secant method
    e = secant (ni, del, e, de);

    //Find the solution u(x)
    u = numerov(nx + 1, h, 0.0, 0.01, e);

    //Output the wavefunction to a file
    ofstream myfile ("Problem 2.txt");
    if (myfile.is_open())
    {
        myfile << "Input" << "\t" << "u(x)" << endl;
        double x = x1;
        double mh = m*h;
        for (int i = 0; i <= nx; i += m)
        {
            myfile << x << "\t" << u.at(i) << endl;
            x += mh;
        }
        myfile.close();
    }

    return 0;
}

```