Определение 3 неизвестных с помощью петель - PullRequest
0 голосов
/ 09 октября 2018

Мне нужно подобрать уравнение для этой кривой косинуса.Уравнение в виде y = A * cos (2 * pi * (время - d) / T), с 3 неизвестными (A, d, T). Данные для оси y - это ydata. Данные для оси x - это время

* 1002.* Прямо сейчас я получаю ошибку «Индекс превышает границы массива».Какие-нибудь советы?Я должен идти этим методом, так как мне нужно использовать математику, чтобы решить это.Я нахожу значения параметров для наименьшей средней ошибки.
% SOLVING FOR 3 PARAMETERS

plot(time,newy)
% Setting the intervals for the amplitude
amp_interval = 21;

% Setting the intervals for the delay
delay_interval = 61;

% Setting the intervals for the period
period_interval = 61;

% Creating a 3D matrix "list_variables"
list_variables = ones(amp_interval,delay_interval,period_interval);

% From plot, I can determine range of rate and constant values
% Set range of amplitude
amp = linspace(9,11,amp_interval);

% Set range of delay
delay = linspace(0,1,delay_interval);

% Set range of period
period = linspace(24,26,period_interval);

% Determining values of rate and constant with help of mean error

% For loop looping through the number of rate intervals
% Counting through for raterow
for   ampX=1:amp_interval;

      % Assigning the value "valuerate" corresponding to the rate for each respective
      % "raterow"
      valueamp = amp(ampX);

      % For loop looping through the number of constant intervals
      % Counting through for constcol
      for delayY = 1:delay_interval;

          % Assigning the value "valueconst" corresponding to the constant for each respective
          % "constcol"
          valuedel = delay(delayY);

           % For loop looping through the number of constant intervals
      % Counting through for constcol
      for periodZ = 1:period_interval;

          % Assigning the value "valueconst" corresponding to the constant for each respective
          % "constcol"
          valueper = period(periodZ);

          % Setting the equation for y = mx + c
          data_curve = valueamp * cos(2*pi * (time - valuedel)/ valueper );

          % Finding mean error "mean_range" - taking the modulous of
          % (predicted value - data value), and then averaging the value.
          mean_range = mean(abs(data_curve - data_model_2));

          % Replacing the "1" values of the matrix to the corresponding mean
          % error for each row and column
          list_variables(ampX,delayY,periodZ) = mean_range;

          % end of for loop looping through the number of period intervals
      end

          % end of for loop looping through the number of delay intervals
      end

      % end of for loop looping through the number of amp intervals
  end

% "lowestmeanr" is the lowest mean error in "list_variables" - and the values of corresponding rate
% and constant is wanted
lowestmeanr = min(min(min(list_variables)));

% Finding the row and column corresponding to lowest mean error
[X,Y,Z] = find(list_variables==lowestmeanr);

% Determined rate from lowest mean error "ratedeter"
ampdeter = amp(X);

% Determined constant from lowest mean error "constdeter"
deldeter = delay(Y);

% Determined constant from lowest mean error "constdeter"
perdeter = period(Z);

% Determined equation for cosine plot
data_curvedeter = ampdeter * cos(2*pi * (time - deldeter)/ perdeter );

% Plotting the determined data by mean value in red
plot(time,data_curvedeter,'r');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...