Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

In this thread, we will be solving Differential Equations through the Euler's Method

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Hi;

You meant numerically solving them of course. We would start on an easy one like

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

**anonimnystefy****Real Member**- From: Harlan's World
- Registered: 2011-05-23
- Posts: 16,016

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

The knowledge of some things as a function of age is a delta function.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

I have that book but I am not going to be using it here.

For the general first order DE:

y′ = f(x, y)

y(x0) = y0 and we want to find y(xn)

We need to define h, this will be easier with an example.

The page I am looking at was nice enough to provide code for the problem!

```
euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:=
Block[{
xold=x0,
yold=y0,
sollist={{x0,y0}},
x,y,h
},
h=N[(xn-x0)/steps];
Do[ xnew=xold+h;
ynew=yold+h*(f/.{x->xold,y->yold});
sollist=Append[sollist,{xnew,ynew}];
xold=xnew;
yold=ynew,
{steps}
];
Return[sollist]
]
```

We will use it! I will give credit to the page at the end of the posting.

The example we will use is

with y(0) = 1.

Are you okay up to here?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

That is very procedural.

Is y(0) = 1 a part of the problem?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Yes, it is the initial condition. It says that when x = 0 that y is 1.

Yes it is procedural. Most people learn that paradigm first so they try to treat M that way.

Ready to use the proggie?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

Please tell me what solving a DE means.

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

I am sure the Topo boys will just shrug their shoulders and smirk to each other over this def but it is how I understand it.

When you solve an equation you find the values of the variable that make the equation true. When you solve a DE you find the functions that make the DE true.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

I am running the code.

What should I key in as f_,{x_,x0_,xn_},{y_,y0_},steps_ ?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

`euler[y, {x, 0, 1}, {y, 1}, 2]`

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

The first argument is the derivative of the function? What are steps?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

```
In[6]:= euler[y, {x, 0, 1}, {y, 1}, 2]
Out[6]= {{0, 1}, {0.5, 1.5}, {1., 2.25}}
```

What does this mean?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

You know that at x=0 (x0, the initial condition) that y = 1. That is the first list {0, 1}. That was easy, it is given in the parameters.

We want the y value at x = 1

The number of steps is 2, notice the program computed two y values.

{0.5, 1.5} the program thinks that at x = .5, y = 1.5

and

{1., 2.25} the program thinks that at x = 1, y = 2.25

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

Agnishom alone can think. Mathematica cannot.

```
In[5]:= euler[f_, {x_, x0_, xn_}, {y_, y0_}, steps_] :=
Block[{xold = x0, yold = y0, sollist = {{x0, y0}}, x, y, h},
h = N[(xn - x0)/steps];
Do[xnew = xold + h;
ynew = yold + h*(f /. {x -> xold, y -> yold});
sollist = Append[sollist, {xnew, ynew}];
xold = xnew;
yold = ynew, {steps}];
Return[sollist]]
In[6]:= euler[y, {x, 0, 1}, {y, 1}, 2]
Out[6]= {{0, 1}, {0.5, 1.5}, {1., 2.25}}
In[7]:= euler[y, {x, 0, 1}, {y, 1}, 3]
Out[7]= {{0, 1}, {0.333333, 1.33333}, {0.666667, 1.77778}, {1.,
2.37037}}
In[10]:= euler[y, {x, 0, 1}, {y, 1}, 50]
Out[10]= {{0, 1}, {0.02, 1.02}, {0.04, 1.0404}, {0.06,
1.06121}, {0.08, 1.08243}, {0.1, 1.10408}, {0.12, 1.12616}, {0.14,
1.14869}, {0.16, 1.17166}, {0.18, 1.19509}, {0.2, 1.21899}, {0.22,
1.24337}, {0.24, 1.26824}, {0.26, 1.29361}, {0.28, 1.31948}, {0.3,
1.34587}, {0.32, 1.37279}, {0.34, 1.40024}, {0.36, 1.42825}, {0.38,
1.45681}, {0.4, 1.48595}, {0.42, 1.51567}, {0.44, 1.54598}, {0.46,
1.5769}, {0.48, 1.60844}, {0.5, 1.64061}, {0.52, 1.67342}, {0.54,
1.70689}, {0.56, 1.74102}, {0.58, 1.77584}, {0.6, 1.81136}, {0.62,
1.84759}, {0.64, 1.88454}, {0.66, 1.92223}, {0.68, 1.96068}, {0.7,
1.99989}, {0.72, 2.03989}, {0.74, 2.08069}, {0.76, 2.1223}, {0.78,
2.16474}, {0.8, 2.20804}, {0.82, 2.2522}, {0.84, 2.29724}, {0.86,
2.34319}, {0.88, 2.39005}, {0.9, 2.43785}, {0.92, 2.48661}, {0.94,
2.53634}, {0.96, 2.58707}, {0.98, 2.63881}, {1., 2.69159}}
In[9]:= euler[y, {x, 0, 1}, {y, 1}, 100]
Out[9]= {{0, 1}, {0.01, 1.01}, {0.02, 1.0201}, {0.03, 1.0303}, {0.04,
1.0406}, {0.05, 1.05101}, {0.06, 1.06152}, {0.07, 1.07214}, {0.08,
1.08286}, {0.09, 1.09369}, {0.1, 1.10462}, {0.11, 1.11567}, {0.12,
1.12683}, {0.13, 1.13809}, {0.14, 1.14947}, {0.15, 1.16097}, {0.16,
1.17258}, {0.17, 1.1843}, {0.18, 1.19615}, {0.19, 1.20811}, {0.2,
1.22019}, {0.21, 1.23239}, {0.22, 1.24472}, {0.23, 1.25716}, {0.24,
1.26973}, {0.25, 1.28243}, {0.26, 1.29526}, {0.27, 1.30821}, {0.28,
1.32129}, {0.29, 1.3345}, {0.3, 1.34785}, {0.31, 1.36133}, {0.32,
1.37494}, {0.33, 1.38869}, {0.34, 1.40258}, {0.35, 1.4166}, {0.36,
1.43077}, {0.37, 1.44508}, {0.38, 1.45953}, {0.39, 1.47412}, {0.4,
1.48886}, {0.41, 1.50375}, {0.42, 1.51879}, {0.43, 1.53398}, {0.44,
1.54932}, {0.45, 1.56481}, {0.46, 1.58046}, {0.47, 1.59626}, {0.48,
1.61223}, {0.49, 1.62835}, {0.5, 1.64463}, {0.51, 1.66108}, {0.52,
1.67769}, {0.53, 1.69447}, {0.54, 1.71141}, {0.55, 1.72852}, {0.56,
1.74581}, {0.57, 1.76327}, {0.58, 1.7809}, {0.59, 1.79871}, {0.6,
1.8167}, {0.61, 1.83486}, {0.62, 1.85321}, {0.63, 1.87174}, {0.64,
1.89046}, {0.65, 1.90937}, {0.66, 1.92846}, {0.67, 1.94774}, {0.68,
1.96722}, {0.69, 1.98689}, {0.7, 2.00676}, {0.71, 2.02683}, {0.72,
2.0471}, {0.73, 2.06757}, {0.74, 2.08825}, {0.75, 2.10913}, {0.76,
2.13022}, {0.77, 2.15152}, {0.78, 2.17304}, {0.79, 2.19477}, {0.8,
2.21672}, {0.81, 2.23888}, {0.82, 2.26127}, {0.83, 2.28388}, {0.84,
2.30672}, {0.85, 2.32979}, {0.86, 2.35309}, {0.87, 2.37662}, {0.88,
2.40038}, {0.89, 2.42439}, {0.9, 2.44863}, {0.91, 2.47312}, {0.92,
2.49785}, {0.93, 2.52283}, {0.94, 2.54806}, {0.95, 2.57354}, {0.96,
2.59927}, {0.97, 2.62527}, {0.98, 2.65152}, {0.99, 2.67803}, {1.,
2.70481}}
In[11]:= euler[y, {x, 0, 1}, {y, 1}, 200]
Out[11]= {{0, 1}, {0.005, 1.005}, {0.01, 1.01003}, {0.015,
1.01508}, {0.02, 1.02015}, {0.025, 1.02525}, {0.03,
1.03038}, {0.035, 1.03553}, {0.04, 1.04071}, {0.045,
1.04591}, {0.05, 1.05114}, {0.055, 1.0564}, {0.06, 1.06168}, {0.065,
1.06699}, {0.07, 1.07232}, {0.075, 1.07768}, {0.08,
1.08307}, {0.085, 1.08849}, {0.09, 1.09393}, {0.095, 1.0994}, {0.1,
1.1049}, {0.105, 1.11042}, {0.11, 1.11597}, {0.115, 1.12155}, {0.12,
1.12716}, {0.125, 1.1328}, {0.13, 1.13846}, {0.135,
1.14415}, {0.14, 1.14987}, {0.145, 1.15562}, {0.15, 1.1614}, {0.155,
1.16721}, {0.16, 1.17304}, {0.165, 1.17891}, {0.17,
1.1848}, {0.175, 1.19073}, {0.18, 1.19668}, {0.185, 1.20266}, {0.19,
1.20868}, {0.195, 1.21472}, {0.2, 1.22079}, {0.205, 1.2269}, {0.21,
1.23303}, {0.215, 1.2392}, {0.22, 1.24539}, {0.225,
1.25162}, {0.23, 1.25788}, {0.235, 1.26417}, {0.24,
1.27049}, {0.245, 1.27684}, {0.25, 1.28323}, {0.255,
1.28964}, {0.26, 1.29609}, {0.265, 1.30257}, {0.27,
1.30908}, {0.275, 1.31563}, {0.28, 1.32221}, {0.285,
1.32882}, {0.29, 1.33546}, {0.295, 1.34214}, {0.3, 1.34885}, {0.305,
1.35559}, {0.31, 1.36237}, {0.315, 1.36918}, {0.32,
1.37603}, {0.325, 1.38291}, {0.33, 1.38982}, {0.335,
1.39677}, {0.34, 1.40376}, {0.345, 1.41078}, {0.35,
1.41783}, {0.355, 1.42492}, {0.36, 1.43204}, {0.365, 1.4392}, {0.37,
1.4464}, {0.375, 1.45363}, {0.38, 1.4609}, {0.385, 1.46821}, {0.39,
1.47555}, {0.395, 1.48292}, {0.4, 1.49034}, {0.405,
1.49779}, {0.41, 1.50528}, {0.415, 1.51281}, {0.42,
1.52037}, {0.425, 1.52797}, {0.43, 1.53561}, {0.435,
1.54329}, {0.44, 1.55101}, {0.445, 1.55876}, {0.45,
1.56655}, {0.455, 1.57439}, {0.46, 1.58226}, {0.465,
1.59017}, {0.47, 1.59812}, {0.475, 1.60611}, {0.48,
1.61414}, {0.485, 1.62221}, {0.49, 1.63032}, {0.495, 1.63848}, {0.5,
1.64667}, {0.505, 1.6549}, {0.51, 1.66318}, {0.515,
1.67149}, {0.52, 1.67985}, {0.525, 1.68825}, {0.53,
1.69669}, {0.535, 1.70517}, {0.54, 1.7137}, {0.545, 1.72227}, {0.55,
1.73088}, {0.555, 1.73953}, {0.56, 1.74823}, {0.565,
1.75697}, {0.57, 1.76576}, {0.575, 1.77459}, {0.58,
1.78346}, {0.585, 1.79238}, {0.59, 1.80134}, {0.595, 1.81035}, {0.6,
1.8194}, {0.605, 1.82849}, {0.61, 1.83764}, {0.615,
1.84682}, {0.62, 1.85606}, {0.625, 1.86534}, {0.63,
1.87467}, {0.635, 1.88404}, {0.64, 1.89346}, {0.645,
1.90293}, {0.65, 1.91244}, {0.655, 1.922}, {0.66, 1.93161}, {0.665,
1.94127}, {0.67, 1.95098}, {0.675, 1.96073}, {0.68,
1.97054}, {0.685, 1.98039}, {0.69, 1.99029}, {0.695, 2.00024}, {0.7,
2.01024}, {0.705, 2.02029}, {0.71, 2.0304}, {0.715,
2.04055}, {0.72, 2.05075}, {0.725, 2.061}, {0.73, 2.07131}, {0.735,
2.08167}, {0.74, 2.09207}, {0.745, 2.10253}, {0.75,
2.11305}, {0.755, 2.12361}, {0.76, 2.13423}, {0.765, 2.1449}, {0.77,
2.15563}, {0.775, 2.1664}, {0.78, 2.17724}, {0.785,
2.18812}, {0.79, 2.19906}, {0.795, 2.21006}, {0.8, 2.22111}, {0.805,
2.23221}, {0.81, 2.24338}, {0.815, 2.25459}, {0.82,
2.26587}, {0.825, 2.27719}, {0.83, 2.28858}, {0.835,
2.30002}, {0.84, 2.31152}, {0.845, 2.32308}, {0.85, 2.3347}, {0.855,
2.34637}, {0.86, 2.3581}, {0.865, 2.36989}, {0.87,
2.38174}, {0.875, 2.39365}, {0.88, 2.40562}, {0.885,
2.41765}, {0.89, 2.42974}, {0.895, 2.44188}, {0.9, 2.45409}, {0.905,
2.46636}, {0.91, 2.4787}, {0.915, 2.49109}, {0.92,
2.50354}, {0.925, 2.51606}, {0.93, 2.52864}, {0.935,
2.54129}, {0.94, 2.55399}, {0.945, 2.56676}, {0.95, 2.5796}, {0.955,
2.59249}, {0.96, 2.60546}, {0.965, 2.61848}, {0.97,
2.63158}, {0.975, 2.64473}, {0.98, 2.65796}, {0.985,
2.67125}, {0.99, 2.6846}, {0.995, 2.69803}, {1., 2.71152}}
```

Are you sure it will converge?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Sometimes we use the phrase thinks in that manner. It means, that is what it got as an answer. It is customary to proceed with a calculation like this with powers of 2.

euler[y, {x, 0, 1}, {y, 1}, 2]

euler[y, {x, 0, 1}, {y, 1}, 4]

euler[y, {x, 0, 1}, {y, 1}, 8]

.

.

.

euler[y, {x, 0, 1}, {y, 1}, 2^14]//Last

Are you sure it will converge?

Surely, you are joking.

Now here is where Brad comes in!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

Who's Brad?

Its slow convergence.

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Recognize that number do you, hmmm?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

```
In[14]:= N[E, 10]
Out[14]= 2.718281828
```

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

So, what do you think it is?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

Euler's number

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Agnishom wrote:

Who's Brad?

You are Brad. The new and improved Brad. You have jumped out of the box.

http://www.mathisfunforum.com/viewtopic … 08#p302808

We can solve that DE analytically quite easily but this is what M gets:

`DSolve[{y'[x] == y[x], y[0] == 1}, y[x], x]`

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

I will run the code a little later, but it seems that f(x) = e^x

I stil do not get it

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

Get what? The numerical solution? The analytical one?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline

I do not get the whole thing about Brad.

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

I'm not crazy, my mother had me tested.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 105,671

That is another thread and another whole concept.

Do you understand what we have done so far concerning the numerical solution of a DE by Euler's method?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.****No great discovery was ever made without a bold guess. **

Offline