MATLAB Answers

Error Reduction in Regression Model

3 views (last 30 days)
hamzah khan
hamzah khan on 1 Sep 2020
Hello,
I have this problem, where I have to estimate force coefficients. I have the time based forces, of which I take the FFT, they are my reference forces. Then I build matrices to numerically estimate those FFT forces. To get the closest estimate, I need to multiply the matrices with some coeficients and I need to find those coefficients.
Here is my code:
%Main Script
% Original coefficients are
coeff_original = [800;200;10;10];
%FFT values when time is from 0.05 till 1.2590
b_reference = [465.9498;243.369;516.6983;452.2795;81.5134;179.418;65.7858;130.3574;58.6862;69.4206];
% Matrices for Esimating FFT of 0,1,2,3,4 order
Fourier_coeff = [-0.343774677078494 -0.420221293933872 -7.01727121110308 -5.72957795130823;0.420221293933872 -0.343774677078494 5.72957795130823 -7.01727121110308;-0.0195319807839135 - 0.207374228023668i -0.214334169775653 - 0.203163837145307i 2.22772613453351 - 2.97069401648263i -1.76676739751800 - 2.94900590421752i;0.214334169775653 + 0.203163837145307i -0.0195319807839135 - 0.207374228023668i 1.76676739751800 + 2.94900590421752i 2.22772613453351 - 2.97069401648263i;0.00648700344488058 - 0.0121247033805691i -0.0758111625117073 - 0.0914951429790348i -1.16516765707854 + 0.0624026969049595i -0.722094909290415 - 0.717554549271970i;0.0758111625117073 + 0.0914951429790348i 0.00648700344488058 - 0.0121247033805691i 0.722094909290415 + 0.717554549271970i -1.16516765707854 + 0.0624026969049595i; -0.00654908785905161 - 0.0247682539100665i -0.0704081380252118 - 0.0388380755068885i 0.675644862253467 + 0.0894650519433900i -0.652483947613814 - 0.486314732529423i; 0.0704081380252118 + 0.0388380755068885i -0.00654908785905161 - 0.0247682539100665i 0.652483947613814 + 0.486314732529423i 0.675644862253467 + 0.0894650519433900i;-0.0148715743865258 - 0.00418105270557728i -0.0566466827112845 - 0.00986732211865589i -0.460065129690790 - 0.560042604092437i -0.617705886360175 - 0.0876662356015614i; 0.0566466827112845 + 0.00986732211865589i -0.0148715743865258 - 0.00418105270557728i 0.617705886360175 + 0.0876662356015614i -0.460065129690790 - 0.560042604092437i]
% Multiplication factor for Fourier Coefficients because FFT values are doubled by Matlab
Y =[1;1;2;2;2;2;2;2;2;2];
% Final matrix A
A= bsxfun(@times,Fourier_coeff,Y); % Ax = b
Pre_Conditioner =[2;0.1;0.05;2;2;2;200;2000.5;0.03;5].^(-1);
V = bsxfun(@times,A,Pre_Conditioner);
b_reference_2 = Pre_Conditioner.*b_reference;
%initial value of coefficients
c = inv(A.'*A)*A.'*b_reference
c = abs(c);
%% to solve the system Ax = b
Starting_Angle = 0;
Total_error = 16;
while Total_error >15
fun = @(x)Solve (x(1),x(2),x(3),x(4),A,Starting_Angle)
% Function to reduce error in Least Squares
[coeff_Numerical] = fminsearch(fun,c)
[Total_error,b_numerical]=Solve_2(coeff_Numerical(1),coeff_Numerical(2),coeff_Numerical(3),coeff_Numerical(4),A,Starting_Angle)
end
% the function Solve is as follows:
function [error] = Solve(x1, x2, x3, x4, A,starting_angle)
% Preconditioner
Pre_Conditioner =[105.738;1073.7;467.6315;31.7839;3.7720;256.0062;94.7778;396.1459;155.5473;48.1352].^(-1);
% FFT values when time is form 0 till 1.2590
%b_reference = [485.9;251.975;358.55;313.6565;85.322;193.4422;53.425;106.66;71.88;84.8653];
%FFT values when time is from 0.5 till 1.2590
%b_reference = [293.5914;151.6237;215.7961;188.6205;50.1612;115.8065;26.0603;64.289;43.225;50.8902];
%FFT values when time is from 0.05 till 1.2590
b_reference = [465.9498;243.369;516.6983;452.2795;81.5134;179.418;65.7858;130.3574;58.6862;69.4206];
% A = bsxfun(@times,A,Pre_Conditioner);
% b_reference = Pre_Conditioner.*b_reference;
x = [x1;x2;x3;x4];
% Solve the equation Ax = b using Least Squares Method
% Numerical Method
b_2 = A*x
b_2 = abs(b_2);
% Error calculation
for i =1:1:size(b_reference,1)
error_percent(i,1) = (abs((b_reference(i)-b_2(i)))/b_reference(i))*100
end
error = error_percent(1,1)+error_percent(2,1)+error_percent(3,1)+error_percent(4,1)+error_percent(5,1)+error_percent(6,1)+error_percent(7,1)+error_percent(8,1)+error_percent(9,1)+error_percent(10,1)
%error = sum(error_percent,1)/size(error_percent,1)
end
% the function Solve_2 is as follows:
function [error,b_2 ] = Solve_2(x1, x2, x3, x4, A,starting_angle)
% Preconditioner
%Pre_Conditioner =[105.738;1073.7;467.6315;31.7839;3.7720;256.0062;94.7778;396.1459;155.5473;48.1352].^(-1);
% FFT values when time is form 0 till 1.2590
%b_reference = [485.9;251.975;358.55;313.6565;85.322;193.4422;53.425;106.66;71.88;84.8653];
%FFT values when time is from 0.5 till 1.2590
%b_reference = [293.5914;151.6237;215.7961;188.6205;50.1612;115.8065;26.0603;64.289;43.225;50.8902];
%FFT values when time is from 0.05 till 1.2590
b_reference = [465.9498;243.369;516.6983;452.2795;81.5134;179.418;65.7858;130.3574;58.6862;69.4206];
%
%
% A = bsxfun(@times,A,Pre_Conditioner);
% b_reference = Pre_Conditioner.*b_reference;
x = [x1;x2;x3;x4];
% Solve the equation Ax = b using Least Squares Method
% Numerical Method
b_2 = A*x % Least Square Estimation
b_2 = abs(b_2);
% Error calculation
for i =1:1:size(b_reference,1)
error_percent(i,1) = (abs((b_reference(i)-b_2(i)))/b_reference(i))*100
end
error = error_percent(1,1)+error_percent(2,1)+error_percent(3,1)+error_percent(4,1)+error_percent(5,1)+error_percent(6,1)+error_percent(7,1)+error_percent(8,1)+error_percent(9,1)+error_percent(10,1)
%error = sum(error_percent,1)/size(error_percent,1)
end
The program is running but the error is not reducing, basically it is an optimisation problem. I find the initial estimate of hte coeff and from those I calculate the simulated forces. Then I find the error between the simulated forces and the reference forces and try to reduce the error by finding different values of coeff.
I am trying to optimise the coeff, which will be near to the original values, I know the original values but the program has to find out by reducing the error.
Does anybody has leads, how to do it? Any thing will be appreaciated
I used lsqnonlin as well, now I am using fminsearch....

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!