# Generating uniform grids

I have the following first order differential equation: $$0.05u'+2xu=0.05^2e^{5-20x^2}$$ for $$x \in [0,1]$$, and $$u(0)=0$$.

then I want to approach the differential equation with a Taylor series at point $$x_i$$, namely: $$u'_{i} \approx \dfrac{u_{i+1}-u_{i}}{h_i}$$.

$$h_i$$ here is the width of the grid, namely $$h_i=x_{i+1}-x_{i}$$. Then I define the grid width $$h_i$$ as follows: $$h_{i+1}=h_i(1+\alpha.h_{i})$$. where alpha is a constant.

when I take $$\alpha$$ values $$1,2,3,4,...,7$$ the error produced around the $$0.15$$ point is quite large.

What alpha value should I take so that the approximation around the $$0.15$$ point has a small error?

Or How do I adjust the hi grid width so that the approximation results obtained are optimal?

• This application of truncated Taylor series is better known as the forward difference quotient. The trapezoidal rule as collocation rule is one order better with about the same effort. Sep 28 at 14:48

The optimal step size has in fact a "w" shape, with the middle leg at about $$x=0.27$$. With $$\tau$$ ($$=10^{-3}$$ in plot) the desired unit-step error in an variable-step Euler implementation, the first bow starts at $$h=3\tau$$, sweeps down to $$h=0.02\tau$$ and returns to $$h=8\tau$$. Then the second bow sweeps down to $$h=0.1\tau$$ at $$x=0.35$$ and then grows exponentially, reaching $$h=10^4\tau$$ at $$x=1$$.
So your step size scheme will indeed have problems if the prescribed step size is not small enough where the first down-swing should be, $$x=0.15$$ being the location of the first minimum.
• If based on $h_{i+1}=h_i(1+\alpha h_i)$, what $\alpha$ value such that value $u$ at $x_i$ optimal? Sep 28 at 17:51
• This model is largely not applicable. Where it is, in the last arc at the larger step sizes, $α$ increases from 20 to 60. So taking an average $α=40$ could work for a while? Note also that approximately $h_i=\frac{h_0}{1-i\,αh_0}$, and this formula has a singularity. This singularity is outside the region where the approximation is valid. But it shows that the initial step size has to be small enough to get reasonable results over the whole interval. Sep 28 at 22:12