integralCalc messing with parameter dimensions

7 views (last 30 days)
I have a program that is supposed to minimize the error of a certain parameter. In order to calculate this value I use the integral function several times and mostly this works fine. However, for certain conditions, during the integration, the function integralCalc comes to these lines:
function [q,errbnd] = iterateScalarValued(u,tinterval,pathlen)
firstFunEval = true;
% Initialize array of subintervals of [a,b].
subs = [tinterval(1:end-1);tinterval(2:end)];
% Initialize partial sums.
q_ok = 0;
err_ok = 0;
% Initialize main loop
while true
% SUBS contains subintervals of [a,b] *where the integral is not
% sufficiently accurate.* The first row of SUBS holds the left
% end points and the second row, the corresponding right
% endpoints.
midpt = sum(subs)/2; % midpoints of the subintervals
halfh = diff(subs)/2; % half the lengths of the subintervals
x = bsxfun(@plus,NODES*halfh,midpt); % NNODES x nsubs
x = reshape(x,1,[]);
[t,w] = u(x); % Transform back to the original domain.
According to this, from what I understand, when the integral is not sufficiently accurate, the program splits it into smaller regions and tries again. The problem is that now it creates some parameters with dimensions of 60 cells instead of the original 150 and when I try to do any mathematical functions with them, I get a matrix dimensions error. This happens when the dimensions of kc and kd in the following line (which in the integral's first try are 150) change to 60, while Jv has dimensions of 150:
Pem=(kc./kd).*(deleps).*(Jv./bulk_dif(Mw));
And the error I get is:
Error using .* Matrix dimensions must agree.
Error in Peclet_fit_fix (line 28) Pem=(kc./kd).*(deleps).*(Jv./bulk_dif(Mw)); %dimensionless
Error in sieving_fit_fix (line 9) Pem=Peclet_fit_fix(kc,kd,Mw,r,sigma,r_avg); %dimensionless
Error in observed_fit_fix>@(rp)sieving_fit_fix(rs,rp,Mw,r,sigma,r_avg).*log_normal_fit(rp,sigma,r_avg).*rp.^4 (line 8) fun=@(r)integral(@(rp)sieving_fit_fix(rs,rp,Mw,r,sigma,r_avg).*log_normal_fit(rp,sigma,r_avg).*rp.^4,1.04*rs,inf)./integral(@(rp)log_normal_fit(rp,sigma,r_avg).*rp.^4,0,inf);
Error in integralCalc/iterateScalarValued (line 323) fx = FUN(t).*w;
Error in integralCalc/vadapt (line 132) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 83) [q,errbnd] = vadapt(@AToInfInvTransform,interval);
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct);
Error in observed_fit_fix>@(r)integral(@(rp)sieving_fit_fix(rs,rp,Mw,r,sigma,r_avg).*log_normal_fit(rp,sigma,r_avg).*rp.^4,1.04*rs,inf)./integral(@(rp)log_normal_fit(rp,sigma,r_avg).*rp.^4,0,inf) (line 8) fun=@(r)integral(@(rp)sieving_fit_fix(rs,rp,Mw,r,sigma,r_avg).*log_normal_fit(rp,sigma,r_avg).*rp.^4,1.04*rs,inf)./integral(@(rp)log_normal_fit(rp,sigma,r_avg).*rp.^4,0,inf);
Error in observed_fit_fix>@(r)flux(r).*fun(r)./((1-fun(r)).*exp(-flux(r)./mass_coeff(r,Mw))+fun(r)).*r (line 9) fun1=@(r) flux(r).*fun(r)./((1-fun(r)).*exp(-flux(r)./mass_coeff(r,Mw))+fun(r)).*r; %nm^2/s
Error in integralCalc/iterateScalarValued (line 314) fx = FUN(t);
Error in integralCalc/vadapt (line 132) [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75) [q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88) Q = integralCalc(fun,a,b,opstruct);
Error in observed_fit_fix (line 11) so_avg = integral(fun1,0,b,'RelTol',10^(-1),'AbsTol',10^(-10))./integral(fun2,0,b,'RelTol',10^(-6),'AbsTol',10^(-10)); %dimensionless
Error in sum_squared2 (line 226) So_mod(i)=observed_fit_fix(Mw,rs,sigma,r_avg);
Error in fminsearch (line 315) x(:) = xe; fxe = funfcn(x,varargin{:});
Error in test_param_fit2 (line 12) ans=fminsearch(@sum_squared2,A,options)
Is there any way to resolve this???

Answers (0)

Categories

Find more on Matrix Computations in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!