Trying to display a plot of navier stokes shock structure, It says error at position(55) "options = optimoptions('fsolve' etc)". Saying " Undefined function or method 'optimoptions' for input arguments of type 'char'." Please, need urgent help?!

8 views (last 30 days)
function shock
%%%%%%%%%%%%%%%
declare certain variables global (i.e. common to other subroutines)
global m1 h0 p0 pr g s u1 t1 u2 t2 mesh mid umid tmid
% clear what is in the figure window
hold off, clf
%Mach number of shock wave
m1= 5
% Set no. of numerical points in shock domain
np = 151;
% Upstream x-boundary
xup = 0;
% Downstream x-boundary
xdown = 20;
% Temperature/viscosity exponent
s = 0.76;
% Set gamma
g = 5/3;
% Set Prandtl number
pr = 2/3;
% Total pressure, enthalpy
p0 = (1 + g*m1*m1)/(g*m1);
h0 = 1 + (g-1)*m1*m1/2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UPSTREAM (1) AND DOWNSTREAM (2) POINTS %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u1 = m1;
t1 = 1/g;
r1 = g;
aa = 1 + (g-1)/2;
bb = -g*p0;
cc = h0;
u2 = (-bb-sqrt(bb*bb-4*aa*cc))/(2*aa);
t2 = u2*(p0-u2);
r2 = r1*u1/u2;
% Straight line initial solution (option)
u = linspace(u1,u2,np);
t = linspace(t1,t2,np);
% Linearly spaced mesh
mesh = linspace(xup,xdown,np).';
% Midpoint values (if needed)
mid = max(find(u>=(u1+u2)/2));
umid = u(mid);
tmid = t(mid);
% set initial solution vector
xs = [u ; t];
%%%%%%%%%%%%%%%%%%%%%%%
% Solve Shock problem %
%%%%%%%%%%%%%%%%%%%%%%%
% accuracy of numerical solution
tol = 1e-6;
% set options for the non-linear equations solver 'fsolve'
options = optimoptions('fsolve',...
'TolX',tol,...
'TolFun',tol,...
'Display','iter-detailed',...
'Algorithm','trust-region-dogleg',...
'FinDiffType','central'...
);
% run solver
[xs,fval,exitflag] = fsolve('ns',xs,options); exitflag
% extract solutions for velocity, temperature, and density
u = xs(1:np);
t = xs(np+1:np*2);
r = (r1*m1)./u;
mesh = mesh(:);
% calculate Maxwellian-mfp equivalent Inverse Density Gradient
mg = max(gradient(r,mesh));
idg = 0.903*mg/(r2-r1);
disp('NS inverse density thickness'), disp(idg)
% plot normalised profiles of velocity and temperature
plot(mesh,(u-u2)./(u1-u2),':',mesh,(t-t1)./(t2-t1),':'); drawnow, hold on
  4 Comments
Geoff Hayes
Geoff Hayes on 20 Jun 2014
Nawaz - try these lines again from the Command Window, do not include them in your program, just try them outside of the program/function
which optimoptions
which fsolve
ver
They will return something.
Nawaz Shahzad
Nawaz Shahzad on 23 Jun 2014
Geoff Ive said what you did on the "command window". It can be seen below, saying optimoptions not found etc.
>> which optimoptions
which fsolve
ver
'optimoptions' not found.
'fsolve' not found.
-------------------------------------------------------------------------------------
MATLAB Version 7.11.0.584 (R2010b)
MATLAB License Number: •••••
Operating System: Microsoft Windows 7 Version 6.1 (Build 7601: Service Pack 1)
Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
-------------------------------------------------------------------------------------
MATLAB Version 7.11 (R2010b)
Simulink Version 7.6 (R2010b)
Communications Toolbox Version 4.6 (R2010b)
Control System Toolbox Version 9.0 (R2010b)
Curve Fitting Toolbox Version 3.0 (R2010b)
Image Acquisition Toolbox Version 4.0 (R2010b)
Image Processing Toolbox Version 7.1 (R2010b)
Neural Network Toolbox Version 7.0 (R2010b)
Signal Processing Toolbox Version 6.14 (R2010b)
SimPowerSystems Version 5.3 (R2010b)
Simulink Control Design Version 3.2 (R2010b)
Statistics Toolbox Version 7.4 (R2010b)
Symbolic Math Toolbox Version 5.5 (R2010b)
System Identification Toolbox Version 7.4.1 (R2010b)
Wavelet Toolbox Version 4.6 (R2010b)

Sign in to comment.

Answers (1)

Matt J
Matt J on 16 Jun 2014
Edited: Matt J on 16 Jun 2014
Either you don't have the Optimization Toolbox installed, or you have a version from before 'optimoptions' was introduced. Try OPTIMSET instead.
  5 Comments
Nawaz Shahzad
Nawaz Shahzad on 23 Jun 2014
Hey Matt J
My university IT help desk said, that Optimization toolbox is not installed. Do you by any chance now another alternative formula for this to work?
Nawaz Shahzad
Nawaz Shahzad on 1 Jul 2014
Matt J, thanks so much. That works, but I was wondering then do you know the next stage, for "run solver". The original when it was optimoptions was
[xs,fval,exitflag] = fsolve('k',xs,options); exitflag
But im not so sure about optimset

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!