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

You are not logged in.

- Topics: Active | Unanswered

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

Hi

I wrote a function in matlab,that implements the Jacobi and Gauss-Seidel method.I have to do this for different matrices..I am facing difficulties when I call my function,giving the Hilbert matrix..

I have to find the error ||x_{k}-d|| (where d is the accurate solution) of the last iteration,with ε=0.000001.I tried to find this and for MAXITERATIONS>=250 I get Nan as result..Isn't it wrong??What should I change?

Offline

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

Hi;

The Hilbert matrix as described in the other thread is notoriously ill conditioned. That is the reason for the problem. You would have to work to many digits of precision or in exact arithmetic. Matlab as far as remember can do neither.

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

Hi;

The Hilbert matrix as described in the other thread is notoriously ill conditioned. That is the reason for the problem. You would have to work to many digits of precision or in exact arithmetic. Matlab as far as remember can do neither.

So,if I am asked to write the error of the last iteration for different n,is the right answer that it is Nan for n>=250??

Offline

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

Also,now I ran the Gauss-Seidel function I wrote for the Hilbert Matrix for MAXITERATIONS>=250..The method does not converge but I get a number,for example for MAXITERATIONS=250 I get this number:1.4455...Why does this happen???

*Last edited by evinda (2013-11-30 01:57:29)*

Offline

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

Are you being asked to use your routine on a Hilbert Matrix?

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

Are you being asked to use your routine on a Hilbert Matrix?

Yes,and I did it using this: hilb(n)..

Offline

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

Which Hilbert Matrix? I will try my routine on it.

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

What do you mean???Which dimension??I wrote this command H=hilb(n) in a function and each time I call it I give different values..The formula for this matrix is

Offline

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

You need to provide 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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

You need to provide the n.

It is given from the user when he calls the function..You could take n=250,to check if you get the same results as mine..

Offline

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

You are trying to invert a 250 x 250 Hilbert Matrix!!!!!!!

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

You are trying to invert a 250 x 250 Hilbert Matrix!!!!!!!

What do you mean???Isn't is possible to do this???

Offline

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

Why are you using such a large matrix?

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

Why are you using such a large matrix?

I have to implement the methods for different values of n,with 50<=n<=1000..

Offline

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

A 250 x 250 Hilbert matrix has a condition number of around 4.35 x 10^380. That means doing arithmetic on it could potentially lose 380 digits of precision.

To show why this is deadly please post what Matlab thinks hilb(4) is.

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

I also have to find the condition number for different values of n and for the 250 x 250 Hilbert matrix,I found it like that: 3.9067e+020..Is it equal with your result,if we consider that Matlab looses a lot of digits of precision??

hilb(4):

1.0000 0.5000 0.3333 0.2500

0.5000 0.3333 0.2500 0.2000

0.3333 0.2500 0.2000 0.1667

0.2500 0.2000 0.1667 0.1429

Offline

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

You are not remembering the other threads. That condition number is kaboobly doo. A Hilbert matrix will not allow arithmetic to be done on it easily. So even when you ask for the condition number it gives the wrong answer! My answer is correct.

Look at Hilbert 4 x 4. It only gives 4 digits! You need 400 digits to get an accurate answer.

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

You are not remembering the other threads. That condition number is kaboobly doo. A Hilbert matrix will not allow arithmetic to be done on it easily. So even when you ask for the condition number it gives the wrong answer! My answer is correct.

Ok,I got it...

Look at Hilbert 4 x 4. It only gives 4 digits! You need 400 digits to get an accurate answer.

So,what does this mean?? Has the precision to do something with the fact that I get Nan as result??? :

Offline

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

This is what a real Hilbert 4 x 4 matrix looks like.

Notice the differences between what Matlab thinks and what really is.

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

Isn't it the same matrix??

1 1/2 1/3 1/4

1/2 1/3 1/4 1/5

1/3 1/4 1/5 1/6

1/4 1/5 1/6 1/7

I have written the command format rat and get now the numbers as fractions..

Offline

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

Do you believe that .3333 and 1 / 3 are the same thing?

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

Do you believe that .3333 and 1 / 3 are the same thing?

No,it is like that: 0.3333333333333333333333333....................................................

Offline

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

Let's do a little experiment, we know that

(1/3) x 900000 = 300000

Enter just as you see it

.3333 x 900000 = ?

**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

**evinda****Member**- Registered: 2013-04-13
- Posts: 105

bobbym wrote:

Let's do a little experiment, we know that

(1/3) x 900000 = 300000

Enter just as you see it

.3333 x 900000 = ?

This is the result I get: 299970

*Last edited by evinda (2013-11-30 04:15:53)*

Offline

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

So you see .3333 is not 1 / 3. When you did a calculation with it the error was magnified until it has a difference of 30.

**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