nonconformant arguments (op1 is 1x1, op2 is 0x0)?

50 views (last 30 days)
Hello,
I was trying to use fsolve funtion to solve two equations but I keep getting nonconformant arguments (op1 is 1x1, op2 is 0x0).
I tried adding . to each operation but still no luck.
Did I do something wrong?
Thanks!
global beta1 beta2 betaOH OH0 totalL totalH V vb;
% Parameters
V0=50e-3;
OH0=0.1024;
totalL=0.2469e-3; % mol
totalH=0.49380e-3; % mol
betaOH=10^-13.78;
beta1=10^9.3431;
beta2=10^11.8922;
vi=0.0001;
pH=[2.675;2.702;2.728;2.765;2.786;2.818;2.852;2.888;2.927;2.968;3.013;...
3.061;3.115;3.174;3.242;3.32;3.412;3.528;3.862;3.914;4.401;7.12;...
8.012;8.31;8.498;8.639;8.756;8.861;8.952;9.036;9.114;9.19;9.262;...
9.332;9.4303;9.476;9.549;9.625;9.703;9.781;9.867;9.957;10.055;10.158;...
10.259;10.363;10.463];
for i=1:length(pH)
x0(1)=0.01*totalL/V0;
x0(2)=0.01*totalH/V0;
V=V0+vi*(i-1);
vb=vi*(i-1);
x = fsolve(@H2L,x0');
end
Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Equation solved, inaccuracy possible. The vector of function values is near zero, as measured by the value of the function tolerance. However, the last step was ineffective. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02. Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 2.000000e+02.
%%function of iminodiacetic acid
%% [L2-]=x(1)
%% [H+]=x(2)
function F = H2L(x)
global beta1 beta2 betaOH OH0 totalL totalH V vb;
F(1) = x(1) + beta1*x(1)*x(2) + beta2*x(1)*(x(2)^2) - totalL/V;
F(2) = x(2) + beta1*x(1)*x(2) + 2*beta2*x(1)*(x(2)^2) - betaOH/x(2)+OH0*vb;
end

Accepted Answer

Torsten
Torsten on 6 Aug 2023
Edited: Torsten on 6 Aug 2023
Works for me (see above). Although the solver doesn't seem to be successful.
You forgot to include the "global" line in the script part of your program.
Try
x = fsolve(@H2L,x0',optimset('Display','none','MaxFunEvals',10000,'MaxIter',10000,'TolFun',1e-10,'TolX',1e-10));
instead of
x = fsolve(@H2L,x0')

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!