Math Is Fun Forum

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

You are not logged in.

#1 2016-06-16 15:04:36

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Polynomial Root Finding

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

#2 2016-06-16 15:06:25

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

Re: Polynomial Root Finding

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

#3 2016-06-16 15:18:44

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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

#4 2016-06-16 15:20:15

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

Re: Polynomial Root Finding

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

#5 2016-06-16 15:23:41

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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

#6 2016-06-16 15:25:49

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

Re: Polynomial Root Finding

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

#7 2016-06-16 15:31:52

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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


'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

#8 2016-06-16 15:33:27

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

Re: Polynomial Root Finding

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

#9 2016-06-16 15:38:27

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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)


'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

#10 2016-06-16 15:41:49

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

Re: Polynomial Root Finding

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

#11 2016-06-16 15:43:26

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

Re: Polynomial Root Finding

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

#12 2016-06-16 15:45:12

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

Re: Polynomial Root Finding

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

#13 2016-06-16 15:46:12

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

Re: Polynomial Root Finding

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

#14 2016-06-16 15:48:43

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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)


'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

#15 2016-06-16 15:51:56

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

Re: Polynomial Root Finding

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

#16 2016-06-16 15:54:25

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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)


'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

#17 2016-06-16 15:55:11

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

Re: Polynomial Root Finding

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

#18 2016-06-16 15:55:16

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

Re: Polynomial Root Finding

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

#19 2016-06-16 15:56:41

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

Re: Polynomial Root Finding

Shift - Enter line 3 again and again.

Offline

#20 2016-06-16 15:57:24

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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

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


'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

#21 2016-06-16 15:58:09

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

Re: Polynomial Root Finding

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

#22 2016-06-16 15:58:55

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

Oh I did not notice the .


'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

#23 2016-06-16 15:59:27

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

Re: Polynomial Root Finding

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

Offline

#24 2016-06-16 16:00:32

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

Re: Polynomial Root Finding

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

#25 2016-06-16 16:01:29

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Polynomial Root Finding

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)


'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

Board footer

Powered by FluxBB