- #1

chopnhack

- 53

- 3

- Homework Statement
- As an introduction to MatLab, we have been given various assignments to get familiar. Now on page nine I find myself getting an empty 1x0 vector instead of the anticipated 5x5 Hilbert matrix.

The problem is to create a 5x5 Hilbert matrix using vectorized statements only, no loops. (The loops I have already completed)

- Relevant Equations
- Each element of the Hilbert matrix is defined by 1/(i+j-1). The solution should look like:

1.0000 0.5000 0.3333 0.2500 0.2000

0.5000 0.3333 0.2500 0.2000 0.1667

0.3333 0.2500 0.2000 0.1667 0.1429

0.2500 0.2000 0.1667 0.1429 0.1250

0.2000 0.1667 0.1429 0.1250 0.1111

My first attempt was:

V=zeros(5,5)

a=1;

i=1:5;

j=1:5;

V(i:j)=a./(i+j-1)

I figured to create a 5x5 with zeros and then to return and replace those values with updated values derived from the Hilbert equation as we move through i and j.

This failed with an error of : Unable to perform assignment because the left and right side have different number of elements.

My next attempt was:

i=1:5;

j=1:5;

V = 1:(1./(i+j-1)):0.111

I began my matrix at 1, just like the Hilbert example, use the Hilbert equation for the decrementer and the end point of the 5x5 is 0.111

This failed with an error of:

V =

1×0 empty double row vector

Can anyone provide some assistance?

Thanks in advance!

V=zeros(5,5)

a=1;

i=1:5;

j=1:5;

V(i:j)=a./(i+j-1)

I figured to create a 5x5 with zeros and then to return and replace those values with updated values derived from the Hilbert equation as we move through i and j.

This failed with an error of : Unable to perform assignment because the left and right side have different number of elements.

My next attempt was:

i=1:5;

j=1:5;

V = 1:(1./(i+j-1)):0.111

I began my matrix at 1, just like the Hilbert example, use the Hilbert equation for the decrementer and the end point of the 5x5 is 0.111

This failed with an error of:

V =

1×0 empty double row vector

Can anyone provide some assistance?

Thanks in advance!