## One Step Method
Applying the Euler formula to the first order equation
\begin{equation} 
y^{'} = sin(x) 
\end{equation}
is approximated by


\begin{equation}
\frac{w_{i+1}-w_i}{h}=sin(x_i)
\end{equation}


Rearranging 
\begin{equation}
w_{i+1}=w_i+hsin(x_i) 
\end{equation}

## DECLARING LIBRARIES


```python
import numpy as np
import math 

%matplotlib inline
import matplotlib.pyplot as plt # side-stepping mpl backend
import matplotlib.gridspec as gridspec # subplots
import warnings
warnings.filterwarnings("ignore")
```

## Setting up X


```python
h=0.1
x_end=10
INITIALCONDITION=1
N=int(x_end/h)
Numerical_Solution=np.zeros(N)
x=np.zeros(N)
Analytic_Solution=np.zeros(N)
```

## NUMERICAL SOLUTION


```python
Numerical_Solution[0]=INITIALCONDITION
x[0]=0
Analytic_Solution[0]=INITIALCONDITION
for i in range (1,N):
    Numerical_Solution[i]=Numerical_Solution[i-1]+h*math.sin(x[i-1])
    x[i]=x[i-1]+h
    Analytic_Solution[i]=2.0-math.cos(x[i])
```

## Plotting


```python
fig = plt.figure(figsize=(8,4))
ax = fig.add_subplot(1,3,1)
plt.plot(x,Numerical_Solution,color='red')
#ax.legend(loc='best')
plt.title('Numerical Solution')
# --- right hand plot
ax = fig.add_subplot(1,3,2)
plt.plot(x,Analytic_Solution,color='blue')
plt.title('Analytic Solution')

#ax.legend(loc='best')
ax = fig.add_subplot(1,3,3)
plt.plot(x,Analytic_Solution-Numerical_Solution,color='blue')
plt.title('Error')

# --- title, explanatory text and save
fig.suptitle('Sine Solution', fontsize=20)
plt.tight_layout()
plt.subplots_adjust(top=0.85)
```


```python

```

65b9fb928d67063987830fcd4c61a372e0d492b2
ipynb
Jupyter Notebook
Chapter 01 - Euler Methods/Supplementary/102_Euler Method Sinewave.ipynb
jjcrofts77/Numerical-Analysis-Python
97e4b9274397f969810581ff95f4026f361a56a2
MIT
2019-09-05T21:39:12.000Z
2022-03-26T14:00:25.000Z
Chapter 01 - Euler Methods/Supplementary/102_Euler Method Sinewave.ipynb
jjcrofts77/Numerical-Analysis-Python
97e4b9274397f969810581ff95f4026f361a56a2
MIT
Chapter 01 - Euler Methods/Supplementary/102_Euler Method Sinewave.ipynb
jjcrofts77/Numerical-Analysis-Python
97e4b9274397f969810581ff95f4026f361a56a2
MIT
2021-06-17T15:34:04.000Z
2022-01-14T14:53:43.000Z
Qwen/Qwen-72B
1. YES
2. YES