这两天遇到这样一个问题, 目前遇到一个函数 F(a,b,c,x), 如果定义a,b,c,可以画出F在x一个区间上的曲线,但无法求得F的具体解析式。 我的目的是把F曲线与手头上的实验曲线达到最好吻合,同时求出相应的参数a,b,c。
目前我的思路是这样的:试验曲线有10000组数据 (x,y),我用最小二乘的思想,求出每一个x上对应的F与y之差平方和,即sum((y-F)^2), 然后给出a, b , c的范围,用fmincon来求解,但是写了程序,发现问题,程序无法求出相应解。错误为 Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 274
In main at 19
Optimization terminated: magnitude of directional derivative in search
direction less than 2*options.TolFun and maximum constraint violation
is less than options.TolCon.
No active inequalities.
请问大神我该怎么办,是函数用错了吗? 还是用别的方法?
主程序如下:
clear all;clc;
global nr nt apt pidt vb freq nfrq
ui=sqrt(-1);
nr=50;
nt=51;
apt=100;
pidt=10d0;
vb=4212;
%% A,b定义约束 45 < x1<55; 0.22 < x2<0.28; 0.0005 < x3<0.001;
A=[1,0,0; 0,1,0;0,0,1;-1,0,0;0,-1,0;0,0,-1];
b=[55,0.28,0.001,-45,-0.22,-0.0005]';
x0= [49.13; 0.2592; 0.0007]; % Starting guess at the solution
[x,fval] = fmincon(@myfun,x0,A,b)
%%_______________________________________
function f = myfun(x);
global nr nt apt pidt vb freq nfrq
adf=load('y_para.dat');
fs=adf(:,1);
con=adf(:,2);
freq=fs;
nfrq=length(freq);
epson= 0.3302 ;
ita=0.6052 ;
c=1.0888 ;
ym=admres(x(1),x(2),epson,ita,c,x(3));
f=sum((real(ym)-con).^2);