- #1
sara_87
- 763
- 0
Homework Statement
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.
Please see the attempt below.
Homework Equations
The Attempt at a Solution
the code:
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).
Any ideas or suggestions will be very much appreciated.
Thank you