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

You are not logged in.

- Topics: Active | Unanswered

We need to find the roots of the following polynomial

Will bobbym please move the relevant posts from the other thread here?

I do not know any numerical methods. This is all I have right now

```
In[3]:= NSolve[x^6 + x^5 - 5 x^4 - 4 x^3 + 6 x^2 + 3 x - 1 == 0]
Out[3]= {{x -> -1.94188}, {x -> -1.49702}, {x -> -0.70921}, {x ->
0.241073}, {x -> 1.13613}, {x -> 1.77091}}
```

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Okay but that is Mathematica showing us what he knows. Does Agnishom have something to add.

You are a programmer, describe iteration.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

bobbym wrote:

Understanding, like love, comes later.

In an iterative root finding process, we start with some seed value and try to improve upon that answer with each iteration, i.e, everytime we touch that value. We do so until the solution is satisfactory to some level of accuracy.

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Newton's is just one form of iteration.

Can you set it up on M?

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

In a purely functional format?

*Last edited by Agnishom (2016-06-16 15:25:37)*

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

M, is both procedural and functional in style.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

Are you asking me to set this up for an arbitrary function?

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

That would be nice and for that you will need M. Which is why I start right off with M.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

Something like this?

I do not understand. The NewtonRaphson function does not take f as an argument in his code.

*Last edited by Agnishom (2016-06-16 15:38:41)*

'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

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

Agnishom wrote:

Something like this?

I do not understand. The NewtonRaphson function does not take f as an argument in his code.

It uses f as a global variable, assigned a value outside of the subroutine, so, to call it for a function, you'd have to set f to that function before calling NewtonRaphson. I assume it works without much problem, but that is a silly thing to do...

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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Here I suggest you use your own head.

f[x_] := x^6 + x^5 - 5 x^4 - 4 x^3 + 6 x^2 + 3 x - 1

x =0.

x = x - f[x]/f'[x]

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**ElainaVW****Member**- Registered: 2013-04-29
- Posts: 580

In an iterative root finding process, we start with some seed value and try to improve upon that answer with each iteration, i.e, everytime we touch that value. We do so until the solution is satisfactory to some level of accuracy.

It's better to say a guess.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Howdy EVW and anonimnystefy!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

How does f' work without trying to name the variable involved? I cannot stop this bothering me. How does the underlying lambda calculus machinery work?

Anyway, here is some of my own code (not to mention that this is very poorly crafted)

```
T[f_, x_] := x - f[x]/f'[x]
Newtons [f_, x0_, n_] := Nest[N[T[f, #]] &, x0, n]
```

And here are some of the roots

```
In[18]:= Newtons[f, #, 100] & /@ Range[-4, 4, 0.5]
Out[18]= {-1.94188, -1.94188, -1.94188, -1.94188, -1.94188, -1.49702, \
-0.70921, -0.70921, 0.241073, 0.241073, 1.13613, 0.241073, 1.77091, \
1.77091, 1.77091, 1.77091, 1.77091}
```

Hello Elaina! Hello stefy!

*Last edited by Agnishom (2016-06-16 15:52:31)*

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Keep it procedural so that we can see what is going on.

Enter this, each in a separate cell.

f[x_] := x^6 + x^5 - 5 x^4 - 4 x^3 + 6 x^2 + 3 x - 1

x =0.

x = x - f[x]/f'[x]

Run line 1 and then line 2.

Now run line 3 repeatedly until the answer stabilizes.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

I edited the last post

After all the hardwork to make it cute and functional?

Now run line 3 repeatedly until the answer stabilizes.

by hand?

*Last edited by Agnishom (2016-06-16 15:57:14)*

'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

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

bobbym wrote:

Here I suggest you use your own head.

f[x_] := x^6 + x^5 - 5 x^4 - 4 x^3 + 6 x^2 + 3 x - 1

x =0.

x = x - f[x]/f'[x]

Well, of course, Newton's method has a number of conditions to be met so that it would converge.

Also, isolating the zeroes might not be a bad idea.

*Last edited by anonimnystefy (2016-06-16 15:57:02)*

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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

Keep running line 3 using M.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

**ElainaVW****Member**- Registered: 2013-04-29
- Posts: 580

Shift - Enter line 3 again and again.

Offline

x = x - f[x]/f'[x]

I think x = N[x - f[x]/f'[x]] is faster?

'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****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

It is not necessary. Line 2 established the N.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

Oh I did not notice the .

'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

**ElainaVW****Member**- Registered: 2013-04-29
- Posts: 580

He should change his screen precision. Six digits are for children.

Offline

**bobbym****bumpkin**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 109,467

As a programmer you should spot things like that. Big difference in how M handles 0 and 0.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**** Always satisfy the Prime Directive of getting the right answer above all else.**

Offline

I am just 14.

It converges quickly.

```
T[f_, x_] := x - f[x]/f'[x]
f[x_] := x^6 + x^5 - 5 x^4 - 4 x^3 + 6 x^2 + 3 x - 1
In[26]:= NestList[N[T[f, #]] &, 0, 10]
Out[26]= {0, 0.333333, 0.241106, 0.241073, 0.241073, 0.241073, \
0.241073, 0.241073, 0.241073, 0.241073, 0.241073}
```

*Last edited by Agnishom (2016-06-16 16:01:58)*

'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