I am new on Matlab and I have some questions about a program I am making.
I am working on a program that creates a vector from tthree other vector by iterations with the following formula :
I would like to create the vector F whcih represent a baseline calculated by iteration from P1, P2 and G which also are vectors with the same number of elements.
Here are the steps I have to follow :
1. Define the vectors, G(t), Pl(t) and P2(t), so that all have an equal number of elements.
2. Set F(t) equal to Pl(t) and evaluate the right-hand side of Eq. 3.
3. Set the evaluated F(t) equal to the input F(t) and perform step 2 again. Repeat this procedure until F(t) does not change further when the output of the preceding iteration is put equal to the input of the next.
I am struggling at step 3. I don't know how to create the loop.
Here is my code for the moment :
dataset = xlsread('ramp.xlsx','A15000:B130000');
x = dataset(:,1);
y = dataset (:,2);
t = 27 : 1 : 218;
P1 = 0.000148 + -0.000182 * t.^1;
P2 = 0.027040 + -0.000329 * t.^1;
G = interp1(x,y,t);
F0 = P1;
Fnew = zeros(1,length(t));
it = 1;
fun = @(t)G-F0;
for ii = 1 : length(t)
Fnew(ii) = (integral(fun,t(1),t(ii),'ArrayValued',true) / integral(fun,t(1),t(end),'ArrayValued',true)) * (P2(ii) - P1(ii)) + P1(ii);
if Fnew(ii) - F0(ii) < 0.1
F0 = Fnew;
it = it+1;
Does anyone have an idea of what is wrong with my code ?
You will find enclosed the excel file related to the code.
Thanks in advance for your help.