# speeding code

I have a problem storing values in an array in Matlab.
If i want to return values according to the formula:
A(v,u)=v u^2-A(v-1,u-1)
where v is the row number and u is the coloumn number.

So, we need to know the previous elements in the matrix to calculate the next.

function A = trying1(n)
A(1,1)=0;
for v=2:n-2
for u=2:v
A(v,u)=v*u^2-A(v-1,u-1);
end
end

will give:

0, 0, 0, 0
0, 8, 0, 0
0, 12, 19, 0
0, 16, 24, 45

if we have n=6.

Fow n=7, we have:

0, 0, 0, 0, 0
0, 8, 0, 0, 0
0, 12, 19, 0, 0
0, 16, 24, 45, 0
0, 20, 29, 56, 80

(the first block is the same as n=6)
However if i put n=20, this will take a longer time because it caluculates the previous already calculated terms again.
I want to store the previous calculated ones so that this reduced the elapsed time (for very big n).
So i want to calculate trying1 for n=1,2,...30 in order.

Any ideas or suggestions will be very much appreciated.
Thank you
Sign In or Register to comment.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!