Matlab:在函数“fminsearch(fun,x0)”中x0 未被接受为矩阵

发布于 2024-11-04 00:29:29 字数 4753 浏览 5 评论 0原文

在函数 fminsearch(fun,x0) 的 Matlab 文档中,x0 可以是标量、向量或矩阵。不过,我尝试将此函数称为:

weight=2;
delta_obj=@(k_to_perturb_annealing) gibbs_sampling_sisim_well_testing(k_to_perturb_annealing);
k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

其中,k_to_perturb_annealing_initial 是 101x82 矩阵。我在行 k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

错误消息:

??? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 195
fv(:,1) = funfcn(x,varargin{:});
Error in ==> optimizing_by_perturbing_SISIM_perm at
31
k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

函数 gibbs_sampling_sisim_well_testing(k_to_perturb_annealing) 上 遇到了错误上面的调用是:

function[obj_fun]=gibbs_sampling_sisim_well_testing(k_to_perturb_annealing)

%% Well parameters

nCell=40000;
A=((sqrt(nCell)*500*sqrt(nCell)*500))/43560; % Area of reservoir in acres
Nw=5; % Number of production wells
xy_wells=[170,130,70,40,20;50,125,190,100,20]; % 1st and 2nd rows represent x and y coordinates respectively
r_investigation=sqrt((A*43560)/(pi*Nw)); % in ft
r_inv_cells=ceil(r_investigation/500);

%% Loading the well testing permeability values for both drawdown and buildup

k_well_testing_dd_sisim=load('k_well_testing_dd_sisim');
k_well_testing_bup_sisim=load('k_well_testing_bup_sisim');

k_dd=struct2cell(k_well_testing_dd_sisim);
k_dd=k_dd{1};

k_bup=struct2cell(k_well_testing_bup_sisim);
k_bup=k_bup{1};

%% Computing the k_eff using well testing perms and k_geomean using reference model of SISIM simulated perms

%# Computing effective permeability value from well testing
k_eff=mean([mean(k_dd),mean(k_bup)]);

%# geomean value of permeability is taken as geomean of 2 times r_inv_cells perm values in X and Y direction around well 1
k_geomean=geomean(geomean(k_to_perturb_annealing));

%# Storing the coordinates of k_to_perturb_annealing

x=max(xy_wells(1,1)-r_inv_cells,1):min(xy_wells(1,1)+r_inv_cells,sqrt(nCell));
y=max(xy_wells(2,1)-r_inv_cells,1):min(xy_wells(2,1)+r_inv_cells,sqrt(nCell));

for i=1:length(x)
    xcoord_k_to_perturb_annealing(1:length(y),i)=x(i);
    ycoord_k_to_perturb_annealing(1:length(y),i)=y;
end

xcoord_k_to_perturb_annealing=reshape(xcoord_k_to_perturb_annealing,(length(y)*length(x)),1);
ycoord_k_to_perturb_annealing=reshape(ycoord_k_to_perturb_annealing,(length(y)*length(x)),1);

%# Changing the gridded k_to_perturb_annealing to a vector form
vector_k_to_perturb_annealing=reshape(k_to_perturb_annealing,(length(y)*length(x)),1);

%% Reading perm_sampledata_for_annealing from gslib .dat file using `gslib_file_to_mat_general.mat' function

nModel_sampledata=3;
nCell_sampledata=20;
nModel_want_sampledata=3;
[perm_sampledata_for_annealing]=gslib_file_to_mat_general(nModel_sampledata,nCell_sampledata,nModel_want_sampledata,'perm_sampledata_5wells_sisim_for_annealing_gslib_format');

%# Separating the contents of file perm values and their coordinates
xcoord_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,1);
ycoord_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,2);
values_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,3);
%% Using variogram.mat function to compute variogram values and lag distances

%# for perm_sampledata_for_annealing

variogram_perm_sampledata=variogram([xcoord_perm_sampledata_for_annealing ycoord_perm_sampledata_for_annealing],values_perm_sampledata_for_annealing,'plotit',false,'nrbins',50,'anisotropy',true);
variogram_perm_sampledata=struct2cell(variogram_perm_sampledata);
gamma_perm_sampledata=variogram_perm_sampledata{1};
theta_perm_sampledata=(variogram_perm_sampledata{2})*(180/pi);
h_perm_sampledata=variogram_perm_sampledata{4};

%# for k_to_perturb_annealing

memory_cells=randperm(2000); % due to lack of memory space, have to use maximum of 2000 points
variogram_k_to_perturb_annealing=variogram([xcoord_k_to_perturb_annealing(memory_cells) ycoord_k_to_perturb_annealing(memory_cells)],vector_k_to_perturb_annealing(memory_cells),'plotit',false,'nrbins',50,'anisotropy',true);
variogram_k_to_perturb_annealing=struct2cell(variogram_k_to_perturb_annealing);
gamma_k_to_perturb_annealing=variogram_k_to_perturb_annealing{1};
theta_k_to_perturb_annealing=(variogram_k_to_perturb_annealing{2})*(180/pi);
h_k_to_perturb_annealing=variogram_k_to_perturb_annealing{4};


%% Optimization and Perturbation

weight=2;
obj_fun=((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ weight)+((k_geomean-k_eff).^weight);

In Matlab documentation for function fminsearch(fun,x0) , x0 can be a scalar, vector, or matrix. However I am trying to call this function as :

weight=2;
delta_obj=@(k_to_perturb_annealing) gibbs_sampling_sisim_well_testing(k_to_perturb_annealing);
k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

Where, k_to_perturb_annealing_initial is 101x82 matrix. I am getting stuck with an error on line k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

Error Message:

??? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 195
fv(:,1) = funfcn(x,varargin{:});
Error in ==> optimizing_by_perturbing_SISIM_perm at
31
k_to_perturb_annealing=fminsearch(delta_obj,k_to_perturb_annealing_initial);

The function gibbs_sampling_sisim_well_testing(k_to_perturb_annealing) I am calling above is:

function[obj_fun]=gibbs_sampling_sisim_well_testing(k_to_perturb_annealing)

%% Well parameters

nCell=40000;
A=((sqrt(nCell)*500*sqrt(nCell)*500))/43560; % Area of reservoir in acres
Nw=5; % Number of production wells
xy_wells=[170,130,70,40,20;50,125,190,100,20]; % 1st and 2nd rows represent x and y coordinates respectively
r_investigation=sqrt((A*43560)/(pi*Nw)); % in ft
r_inv_cells=ceil(r_investigation/500);

%% Loading the well testing permeability values for both drawdown and buildup

k_well_testing_dd_sisim=load('k_well_testing_dd_sisim');
k_well_testing_bup_sisim=load('k_well_testing_bup_sisim');

k_dd=struct2cell(k_well_testing_dd_sisim);
k_dd=k_dd{1};

k_bup=struct2cell(k_well_testing_bup_sisim);
k_bup=k_bup{1};

%% Computing the k_eff using well testing perms and k_geomean using reference model of SISIM simulated perms

%# Computing effective permeability value from well testing
k_eff=mean([mean(k_dd),mean(k_bup)]);

%# geomean value of permeability is taken as geomean of 2 times r_inv_cells perm values in X and Y direction around well 1
k_geomean=geomean(geomean(k_to_perturb_annealing));

%# Storing the coordinates of k_to_perturb_annealing

x=max(xy_wells(1,1)-r_inv_cells,1):min(xy_wells(1,1)+r_inv_cells,sqrt(nCell));
y=max(xy_wells(2,1)-r_inv_cells,1):min(xy_wells(2,1)+r_inv_cells,sqrt(nCell));

for i=1:length(x)
    xcoord_k_to_perturb_annealing(1:length(y),i)=x(i);
    ycoord_k_to_perturb_annealing(1:length(y),i)=y;
end

xcoord_k_to_perturb_annealing=reshape(xcoord_k_to_perturb_annealing,(length(y)*length(x)),1);
ycoord_k_to_perturb_annealing=reshape(ycoord_k_to_perturb_annealing,(length(y)*length(x)),1);

%# Changing the gridded k_to_perturb_annealing to a vector form
vector_k_to_perturb_annealing=reshape(k_to_perturb_annealing,(length(y)*length(x)),1);

%% Reading perm_sampledata_for_annealing from gslib .dat file using `gslib_file_to_mat_general.mat' function

nModel_sampledata=3;
nCell_sampledata=20;
nModel_want_sampledata=3;
[perm_sampledata_for_annealing]=gslib_file_to_mat_general(nModel_sampledata,nCell_sampledata,nModel_want_sampledata,'perm_sampledata_5wells_sisim_for_annealing_gslib_format');

%# Separating the contents of file perm values and their coordinates
xcoord_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,1);
ycoord_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,2);
values_perm_sampledata_for_annealing=perm_sampledata_for_annealing(:,3);
%% Using variogram.mat function to compute variogram values and lag distances

%# for perm_sampledata_for_annealing

variogram_perm_sampledata=variogram([xcoord_perm_sampledata_for_annealing ycoord_perm_sampledata_for_annealing],values_perm_sampledata_for_annealing,'plotit',false,'nrbins',50,'anisotropy',true);
variogram_perm_sampledata=struct2cell(variogram_perm_sampledata);
gamma_perm_sampledata=variogram_perm_sampledata{1};
theta_perm_sampledata=(variogram_perm_sampledata{2})*(180/pi);
h_perm_sampledata=variogram_perm_sampledata{4};

%# for k_to_perturb_annealing

memory_cells=randperm(2000); % due to lack of memory space, have to use maximum of 2000 points
variogram_k_to_perturb_annealing=variogram([xcoord_k_to_perturb_annealing(memory_cells) ycoord_k_to_perturb_annealing(memory_cells)],vector_k_to_perturb_annealing(memory_cells),'plotit',false,'nrbins',50,'anisotropy',true);
variogram_k_to_perturb_annealing=struct2cell(variogram_k_to_perturb_annealing);
gamma_k_to_perturb_annealing=variogram_k_to_perturb_annealing{1};
theta_k_to_perturb_annealing=(variogram_k_to_perturb_annealing{2})*(180/pi);
h_k_to_perturb_annealing=variogram_k_to_perturb_annealing{4};


%% Optimization and Perturbation

weight=2;
obj_fun=((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ weight)+((k_geomean-k_eff).^weight);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-11-11 00:29:29

我认为你的问题是

obj_fun=((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ weight)+((k_geomean-k_eff).^weight);

你需要将 ((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ Weight) 更改为标量,因为 k_geomean 是一个标量

尝试使用 (norm((gamma_perm_sampledata-gamma_k_to_perturb_annealing),2)^weight),或者(norm((gamma_perm_sampledata-gamma_k_to_perturb_annealing),'fro')^weight) 或 ...

I think your problem is

obj_fun=((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ weight)+((k_geomean-k_eff).^weight);

you need to change ((gamma_perm_sampledata-gamma_k_to_perturb_annealing).^ weight) into a scalar as k_geomean is a scalar

try to use (norm((gamma_perm_sampledata-gamma_k_to_perturb_annealing),2)^weight), or (norm((gamma_perm_sampledata-gamma_k_to_perturb_annealing),'fro')^weight) or ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文