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

时间:2011-04-29 02:01:57

标签: matlab matrix mathematical-optimization nonlinear-functions

在函数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);

1 个答案:

答案 0 :(得分:1)

我认为你的问题是

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)或...