matlab - MATLAB 的最小化问题没有给出预期的结果
问题描述
我试图找到最小化函数的系数。根据我所做的一些猜测,我创建了一些具有相同功能的假数据。我想根据假数据找到系数来验证我的代码,但我得到了意想不到的结果。两条线都应该在彼此之上,因为这绝对是函数可以做的事情。
我不确定我的代码哪里出错了,如果你能提供任何帮助,我将不胜感激。代码如下,我还上传了重新创建结果所需的所有文件。
%% Location of point forces
xx = [1.5, 1.5, -0.5,0.4, 0.4]; % X Location of stokeslets
yy = [-3, 3, 0,1.25, -1.25]; % Y Location of stokeslets
pfl = [0, 0]; %Location of the potential flow [x y]
%% Import fake data
load('fakemodel.mat')
%% Optimization
simply_velo = @(sf_arg) velopt(posx,posy,sf_arg,xx,yy,sf_arg(:,6),pfl); %calculates function to minimize at poins where I have data
%function to minimize
fun = @(sf_arg) nan_norm(((speed_fake - simply_velo(sf_arg)).^2)); %relative error
%% Create the non linear constraint
sf_ini = [1.5,1.5,3,-3,-3,6]; %initial guess for variables
A = [0 0 0 1 0 0; 0 0 0 0 1 0; -1 -1 0 0 0 0; 0 0 0 0 0 -1; 0 0 -1 0 0 0]; %A*x < b
b = [0; 0; 0; 0;0]; % b = ()
Aeq = [1 -1 0 0 0 0; 0 2 -1 0 0 0; 0 0 0 -1 1 0; 1 1 1 1 1 0]; %Aeq *x = beq
beq = [0; 0; 0 ;0]; %beq
error = zeros(50,6);
sav_fm = zeros(50,6);
for i = 1 : 50
sf_ini = rand(size(sf_ini));
% options = optimset('Display', 'iter', 'MaxFunEvals', 600,'PlotFcns',@optimplotfval,'TolFun',1e-4,'TolX',1e-4);
options = optimset('MaxFunEvals', 6000,'TolFun',1e-15,'TolX',1e-15);
[fm, fval] = fmincon(fun,sf_ini,A,b, Aeq, beq,[],[],[],options); %f min search
sav_fm(i,:) = fm(:);
Fval(i) = fval;
end
% saved_fm
[minfval,index] = min(Fval);
soln = sav_fm(index,:)
我不确定我的问题出在哪里。欢迎任何建议。
解决方案
推荐阅读
- html - 是否有替代已弃用的 HTML 标记来获得相同的输出,以便将页面划分为所需的列数?
- c# - IOException on Directory.Move 使用该目录的进程后
- forms - 表单验证如何排除输入字段?
- javascript - 类型错误:无效的 URL
- server - 服务器无法处理请求。---> 客户端发现响应内容类型为“text/html”,但预期为“text/xml”
- spring-boot - 找不到类型的字段所需的 bean。错误 springboot API 部署到 ubuntu
- ios - 无法在我的 iOS 应用程序中访问我的可可框架的 .json 文件
- c# - 如何在插入数据库时将类属性的值设置为另一个类的生成 id 值?
- asp.net-mvc - 将 Google Drive API 托管到 IIS 后上传失败。将错误显示为无法启动浏览器
- amazon-cloudfront - 删除 service-worker.js(特殊情况)