MATLAB fminsearch equation using four anonymous pa

2019-08-28 13:22发布

问题:

I am a new MATLAB user and I need to find four co-efficients of an equation which calculates the core losses in an electric motor.

I have already plotted the measured data on a graph and need to use these results to define an equation for this graph.

The equation for the core loss:

From the measured results I have plotted the values of Pfe(Bm) for different values of f, but I need the values for a, b, e and x.

Using the equation:

I can calculate the minimum value for the error, E by means of a nonlinear regression analysis, where Pfei is my measured value and Pfei* is my estimated value (in which case I would probably 'guess' the initial values of the co-efficients).

How do I use the fminsearch function to calculate the minimum error value, and consequently calculate the values of the above mentioned co-efficients?

回答1:

You can do something like the code below. The vector fitParams will have the values of a, b, e, and x.

function [fitParams, fval] = callMinEx()
Bm = 1:100;

% fake data.  Use your actual data for pfei
x0 = [2,3,4,5];
pfei = coreLoss(Bm, x0) + 5e10*rand(1,length(Bm));

% call fminsearch with some initial parameters
startParams = [3,3,3,3];
[fitParams,fval] = fminsearch(@func2Minimize, startParams);

% plot data and fit
plot(Bm,pfei,'r*');
hold on
plot(Bm, coreLoss(Bm, x0));
legend('data','fit')

     % The equation to be minimized by fminsearch
    function epsValue = func2Minimize(params)
        pfeStar = coreLoss(Bm,params);
        epsValue = sum(((pfei - pfeStar) ./ pfei).^ 2);
    end

    % core loss function
    function pfei = coreLoss(Bm, x0)
        a = x0(1);
        b = x0(2);
        e = x0(3);
        x = x0(4);

        f = 100;

        pfei =  a * f * Bm .^ x + b * (f * Bm).^2 + e * (f * Bm).^1.5;
    end

end