0

I am working on a regulation for a vehicle. I have the following formula for the signal processing of the signals that go into the controller:

heightDiff = k1*A + k2*B + k3*C

I can vary the pre-factors k1, k2, k3. Depending on how I change the pre-factors, the system behaves differently. Now I want to determine the best pre-factors k1, k2, k3 so that the system behaves best. How can I do this? A, B, C describe the input signals in this formula. I have already tried to find the optimum parameters using the gradient descent method. However, it is difficult for me to define a model function that describes my problem.

During several attempts, I determined the sum of squared errors and then described the following model function:

predicted_data = k1 * k1_values + k2 * k2_values + k3 * k3_values;

k1_values etc. are values that I have varied in experiments. However, I am of the opinion that this model function is not really optimal because I then obtain pre-factor values for k1, k2, k3, which show in a subsequent measurement that the PArameters are not optimal.

As a note: I work with Matlab/Simulink

I tried to solve the whole thing using the gradient descent method in Matlab. Here is my code:

measured_data =[ ... ];
% experimental data 
k1_values = [...];
k2_values = [...];
k3_values = [...];


% Start values for k1, k2, k3
k1 = 1;
k2 = 1;
k3 = 1;
params = [k1, k2, k3];
% Number of iterations
max_iterations = 100000;
tolerance = 1e-4; % Tolerance for convergence

% Iterative improvement of the parameters
for iter = 1:max_iterations

    %Model function 
    predicted_data = k1 * k1_values + k2 * k2_values + k3 * k3_values;
    
    %sum of the quadratic errors 
    error = sum((measured_data - predicted_data).^2);

    a = params(1);
    b = params(2);
    c = params(3);

    %output for each iteration
    %disp(['Iteration ', num2str(iter), ', error = ', num2str(error)]);
    
    % check for convergence
    if error < tolerance
        disp('Convergence reached.');
        break;
    end
    
    % Update parameters k1, k2, k3 (simple adjustment)
    k1 = k1 - 0.1 * sign(predicted_data - measured_data) * k1_values';
    k2 = k2 - 0.1 * sign(predicted_data - measured_data) * k2_values';
    k3 = k3 - 0.1 * sign(predicted_data - measured_data) * k3_values';
   % disp (num2str(k1));
end

% Output optimal parameters
disp('Optimal parameters:');
disp(['k1: ', num2str(k1)]);
disp(['k2: ', num2str(k2)]);
disp(['k3: ', num2str(k3)]);

0