Optimoptions - Invalid solver specified error

7 views (last 30 days)
Hi, please can someone have a look at mycode to see what's wrong. I keep getting this error message. Thank you
Error using optimoptions
Invalid solver specified. Provide a solver name or handle (such as 'fmincon' or
@fminunc).
Type DOC OPTIMOPTIONS for a list of solvers.
Error in solveModel (line 57)
opt = optimoptions(@fsolve,'Display','iter-detailed','FunValCheck','on','MaxFunctionEvaluations',10000000,'MaxIteration',maxIter,'StepToleance',1e-6,'FunctionTolerance',1e-6);,
%% Solve membrane model
% Description: This script defines feed and membrane parameters, the number
% of collocation points, initial values of the dimensionless model
% variables, and solves the model equations for membrane with
% counter-current flow pattern.
%
% Variables:
% HFperm :: Permeances for the hollow fiber carbon membrane for [O2 N2]
% param :: struct consisting of the following membrane parameters
% perm - matrix of the permeances [kmol/kPa*h*m2]
% area - effective membrane area [m2]
% R - universal gas constant [m3*kPa/(K*mol)]
%
% Feed :: strict consisting of the following feed parameters
% Ns - Shell side flow rate for [O2 N2]
% Nt - Fiber side folw rate for [O2 N2]
% Ps - Feed side pressure [kPa]
% Pt - Permeate side pressure [kPa]
clc
clear all
%% Creating a param struct where membrane parameters are stored.
HFperm = 1e-03*[16.8e-03 3.36e-03];
param.Perm = HFperm;
param.Area = 47.7;
param.Visc = 14.9e-09/3600;
param.R = 8.314;
%% Creating a feed struc where known values for the feed at shell and tube side are stored.
feed.Ns = 0.44*[0.209 0.791];
feed.Nt = zeros(1,2);
feed.Ps = 1034;
feed.Pt = 103.4;
feed.Ts = 273.15 + 20;
%% Orthogonal collocation method and Fsolve
% Discretize and approximate model equation residuals
n = 2;
z = [0 1/2-sqrt(21)/14 1/2 1/2+sqrt(21)/14 1];
A = [0.278 -0.202 0.169 -0.071; ...
0.398 0.069 0.064 -0.031; ...
0.387 0.234 0.278 -0.071;
0.389 0.222 0.389 0.000];
Y0=ones(n+2,4);
%Initial values
Y0(:,1) = 0.4;
Y0(:,2) = 0.1;
Y0(:,3) = 0.03;
Y0(:,4) = 0.97;
%Optimization settings for the solver
maxIter = 2000;
opt = optimoptions(@fsolve,'Display','iter-detailed','FunValCheck','on','MaxFunctionEvaluations',10000000,'MaxIteration',maxIter,'StepTolerance',1e-6,'FunctionTolerance',1e-6);
t0 = tic;
[Y, fval, exitflag, output]=fsolve(@(Y) model_MB(Y, A, n, param, feed),Y0,opt);
Norm of First-order Trust-region Iteration Func-count f(x) step optimality radius 0 17 1.26878 1.19 1 1 34 0.519374 1 0.337 1 2 51 0.428702 2.5 0.569 2.5 3 68 0.334533 2.5 0.146 2.5 4 85 0.287467 6.25 0.303 6.25 5 102 0.25163 6.25 0.12 6.25 6 119 0.232424 15.625 0.452 15.6 7 136 0.203663 15.625 0.101 15.6 8 153 0.171875 39.0625 0.954 39.1 9 170 0.121609 39.0625 0.169 39.1 10 187 0.0961458 97.6563 0.571 97.7 11 204 0.0671728 97.6562 0.118 97.7 12 205 0.0671728 244.141 0.118 244 13 222 0.0542653 61.0352 0.438 61 14 239 0.0281923 152.588 2.83 153 15 240 0.0281923 380.885 2.83 381 16 257 0.0157762 95.2212 0.569 95.2 17 274 0.000715115 238.053 0.106 238 18 275 0.000715115 48.8918 0.106 595 19 292 0.000384456 12.2229 0.2 12.2 20 309 3.6133e-05 30.5574 1.37 30.6 21 310 3.6133e-05 6.4665 1.37 76.4 22 327 6.9901e-06 1.61662 0.39 1.62 23 344 1.25641e-06 4.04156 13.8 4.04 24 345 1.25641e-06 0.512592 13.8 4.04 25 362 7.58608e-08 0.128148 4.38 0.128 26 363 7.58608e-08 0.132648 4.38 0.32 27 380 6.66623e-09 0.0331621 1.52 0.0332 28 381 6.66623e-09 0.075564 1.52 0.0829 29 398 1.17994e-09 0.018891 0.397 0.0189 30 415 1.00171e-09 0.0472275 26.8 0.0472 31 416 1.00171e-09 0.0472275 26.8 0.0472 32 433 8.77872e-10 0.0118069 26.7 0.0118 33 434 8.77872e-10 0.0118069 26.7 0.0118 34 451 7.89096e-11 0.00295172 8.05 0.00295 35 452 7.89096e-11 0.00737929 8.05 0.00738 36 469 2.51055e-11 0.00184482 4.51 0.00184 37 486 2.26848e-11 0.00184482 4.31 0.00184 38 487 2.26848e-11 0.00184482 4.31 0.00184 39 504 3.02338e-12 0.000461206 1.29 0.000461 40 505 3.02338e-12 0.00115301 1.29 0.00115 41 522 1.68554e-12 0.000288254 0.714 0.000288 42 539 1.62199e-12 0.000288254 0.677 0.000288 43 540 1.62199e-12 0.000288254 0.677 0.000288 44 557 1.14061e-12 7.20634e-05 0.202 7.21e-05 fsolve stopped because the sum of squared function values, r, changed by 2.406920e-13 relative to its initial value; this is less than max(options.FunctionTolerance^2,eps) = 1.000000e-12. r = 1.140608e-12, is less than sqrt(options.FunctionTolerance) = 1.000000e-03.
tf = toc(t0);
disp(tf);
0.2754
%Plotting the results
Area = param.Area*z;
Res = sum(feed.Ns)*Y(:,1:4);
modelPlot(Area, Res)
Unrecognized function or variable 'modelPlot'.
function F=model_MB(Y,A,n, param, feed)
%Dimensionless variables
Nty = Y(:,1:2);
Nsx = Y(:,3:4);
Pt = feed.Pt/feed.Ps;
Ps = feed.Ps/feed.Ps;
%Dimensionless constants
Kj = param.Area*feed.Ps*param.Perm(1,:)/(sum(feed.Ns));
%Preallocates memory for the set of residuals
F = zeros(n+2,4);
%%Boundary conditions at z=0
dJ1 = (Ps*(Nsx(1,:)/sum(Nsx(1,:)))-Pt*(Nty(1,:)/sum(Nty(1,:))));
F(1,1:2) = Nty(1,:)-feed.Nt/sum(feed.Ns);
F(1,3:4) = A(1,:)*Nsx - Kj.*dJ1;
%%Inner collocation points:
for i=2:n+1
dJi = (Ps*Nsx(i,:)/sum(Nsx(i,:)) - Pt*Nty(i,:)/sum(Nty(i,:)));
F(i,1:2) = A(i,:)*Nty - Kj.*dJi;
F(i,3:4) = A(i,:)*Nsx - Kj.*dJi;
end
%%Boundary conditions at last collocation point, z=n+2
dJn = (Ps*Nsx(n+2,:)/sum(Nsx(n+2,:))-Pt*Nty(n+2,:)/sum(Nty(n+2,:)));
F(n+2,1:2) = A(n+2,:)*Nty - Kj.*dJn;
F(n+2,3:4) = Nsx(n+2,:) - feed.Ns/sum(feed.Ns);
end

Accepted Answer

Bruno Luong
Bruno Luong on 6 Nov 2022
Edited: Bruno Luong on 6 Nov 2022
Check if you have license and installed optimization toolbox by typing
ver

More Answers (1)

Torsten
Torsten on 5 Nov 2022
You wrote
'StepToleance'
instead of
'StepTolerance'
...
  7 Comments
Torsten
Torsten on 6 Nov 2022
Edited: Torsten on 6 Nov 2022
Corrected and code works now.
I still can't read the optimoptions line of your code from the image.
As Bruno Luong noted you should check whether you have licensed and installed the optimization toolbox.
See if this simple example works with your MATLAB:
fun = @(x)x.^2-1;
sol = fsolve(fun,2)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the value of the function tolerance, and the problem appears regular as measured by the gradient.
sol = 1.0000

Sign in to comment.

Categories

Find more on Quadratic Programming and Cone Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!