# [Solved] Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler in python. So Here I am Explain to you all the possible solutions here.

## How Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler Error Occurs?

Today I get the following error Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler in python.

## How To Solve Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler Error ?

1. How To Solve Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler Error ?

To Solve Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler The problem, as the Traceback says, comes from the line `x[i+1] = x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] )`.

2. Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler

To Solve Index: index 1 is out of bounds for axis 0 with size 1/ForwardEuler The problem, as the Traceback says, comes from the line `x[i+1] = x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] )`.

## Solution 1

The problem is with your line

```x=np.array ([x0*n])
```

Here you define x as a single-item array of -200.0. You could do this:

```x=np.array ([x0,]*n)
```

or this:

```x=np.zeros((n,)) + x0
```

Note: your imports are quite confused. You import numpy modules three times in the header, and then later import pylab (that already contains all numpy modules). If you want to go easy, with one single

```from pylab import *
```

line in the top you could use all the modules you need.

## Solution 2

The problem, as the Traceback says, comes from the line `x[i+1] = x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] )`. Let’s replace it in its context:

• x is an array equal to [x0 * n], so its length is 1
• you’re iterating from 0 to n-2 (n doesn’t matter here), and i is the index. In the beginning, everything is ok (here there’s no beginning apparently… 🙁 ), but as soon as `i + 1 >= len(x)` <=> `i >= 0`, the element `x[i+1]` doesn’t exist. Here, this element doesn’t exist since the beginning of the for loop.

To solve this, you must replace `x[i+1] = x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] )` by `x.append(x[i] + ( t[i+1] - t[i] ) * f( x[i], t[i] ))`.

## Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.