I am trying to interpret a series of data iteratively, but am having a problem with my arrays not being the same size (Error: Matrix dimensions must agree).
The problem is, I have a series of data points that are calculated and I must then take the derivative of that data set and compare the derivative to the original data set, and do this multiple times until the difference is within a convergence factor.
For example: say I have an initial data set A_o, which is a 1000×1 matrix. I then take the derivative of A_o (which I have called A_i), which returns a 999×1 matrix. I then need to compare the difference between A_o and A_i to see if they are within a set convergence factor, and if not, re-run the calculation with A_i now taking the place of A_o and A_i+1 being the derivative of A_i. So A_i+1 will be a 998×1 matrix, and so on. I have chosen to set this up using a while loop.
Everytime I take the derivative, it makes the arrays a different size and thus the code will not run. I also have to multiply this by another data set (I have called 'I') as well. Essentially, I don't know how to systematically reduce the size of my array by 1 point each time it goes through the loop.
Any help would be greatly appreciated. I have attatched the problematic part of the code below.
% A_0 is my inital array of data, calulated and brought in from another function.
% I is another array of data with the same number of data points as A_0
dt = 0.2 % A set time interval between datapoints
A_i = (diff(A_0)/dt).*I.^2; %My equation to get to the next iteration using the derivative of A_0
conv_con = A_0 - A_i;while conv_con > 1e-9 A_0 = A_0 + A_i; A_i = (diff(A_0)/dt).*I.^2;end
Best Answer