Optimoptions - Invalid solver specified error
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Trang
 el 5 de Nov. de 2022
  
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);
tf = toc(t0);
disp(tf);
%Plotting the results
Area = param.Area*z;
Res = sum(feed.Ns)*Y(:,1:4);
modelPlot(Area, Res)
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
0 comentarios
Respuesta aceptada
  Bruno Luong
      
      
 el 6 de Nov. de 2022
        
      Editada: Bruno Luong
      
      
 el 6 de Nov. de 2022
  
      Check if you have license and installed optimization toolbox by typing
ver
0 comentarios
Más respuestas (1)
  Torsten
      
      
 el 5 de Nov. de 2022
        You wrote
'StepToleance'
instead of
'StepTolerance'
...
7 comentarios
  Torsten
      
      
 el 6 de Nov. de 2022
				
      Editada: Torsten
      
      
 el 6 de Nov. de 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)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



