使用四个匿名参数的MATLAB fminsearch方程 [英] MATLAB fminsearch equation using four anonymous parameters
问题描述
我是MATLAB的新用户,我需要找到一个方程的四个系数来计算电动机的铁损.
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.
铁损的等式:
从测量结果中,我绘制了 f 的不同值的 Pfe (Bm)值,但是我需要 a , b , e 和 x .
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.
使用公式:
我可以通过非线性回归分析来计算误差的最小值 E ,其中 Pfei 是我的测量值, Pfei *是我的估计值(在这种情况下,我可能会猜测"系数的初始值).
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).
如何使用fminsearch
函数计算最小误差值,并由此计算上述系数的值?
How do I use the fminsearch
function to calculate the minimum error value, and consequently calculate the values of the above mentioned co-efficients?
推荐答案
您可以执行以下代码.向量fitParams
将具有a,b,e和x的值.
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
这篇关于使用四个匿名参数的MATLAB fminsearch方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!