Why am I getting this error? Error using feval Unrecognized function or variable 'emul'

20 views (last 30 days)
%% Oil/Water System at 30C (Paraffin)
mu1 = 3.8; % Viscosity in mPa.s-1
rho_O1 = 797; % Oil Density in kg/m3
rho_B1 = 998; % Brine Density in kg/m3
IFT1 = 21; % Interfacial Tension mN/m
g = 9.81; % m2/s
% Concentration for this system is 80ppm
%% Oil/Water System at 40C (Crude Oil A)
mu2 = 5; % Viscosity in mPa.s-1
rho_O2 = 833; % Oil Density in kg/m3
rho_B2 = 994; % Brine Density in kg/m3
IFT2 = 5; % Interfacial Tension mN/m
% Concentration for this system is 200ppm
%% Oil/Water System at 50C (Crude Oil B)
mu3 = 6; % Viscosity in mPa.s-1
rho_O3 = 834; % Oil Density in kg/m3
rho_B3 = 989; % Brine Density in kg/m3
IFT3 = 3; % Interfacial Tension mN/m
% Concentration for this system is 200ppm
%% Oil/Water System at 60C (Crude Oil C)
mu4 =4.9; % Viscosity in mPa.s-1
rho_O4 = 826; % Oil Density in kg/m3
rho_B4 = 985; % Brine Density in kg/m3
IFT4 = 1; % Interfacial Tension mN/m
%Concentration for this system is 200ppm
function dh_s = emul(t,hs)
nd = 1000; % No. of Droplets
Vol = 900; % Liquid volume of emulsion (ml)
l = 0.5; % Mean Distance between droplets
alpha = 0.08; % Empirical Collision Effiency Parameter
D0 = 300; % Initial Droplet Diameter (microns)
Pr = 0.74; % Volume Fraction
Pr0 = ((nd*pi*D0^3)/6)/Vol; % Initial Volume Fraction of droplet
Prm = ((nd*pi*((D0+l)^3))/6)/Vol; % Maximum Volume Fraction of droplet
delrho = rho_B1 - rho_O1; % difference between the dispersed water and continuous oil phase
Vsto = (delrho*g*(D0^2))/18*mu1; % Settling Velocity of Hard Spheres (stoke's velocity)
fPr = (1-Pr0)^5.3; % Dimensionless
%D = sqrt((2/3)*alpha*((Vsto*fPr)/(((Prm/Pr0)^1/3)-1))*(D0*t)+(D0^2)); % evolution of average diameter versus time
K1 = ((2/3)*alpha*((Vsto^2)/D0))*((fPr^2)/((Prm/Pr)^1/3)-1);
dh_s = -K1*t-(Vsto*fPr);
end

Answers (2)

Walter Roberson
Walter Roberson on 7 Mar 2022
When you use a quoted string as the routine to invoke, then remember that the string will be interpreted inside a function several levels down in the ode* routine. That function has no way of climbing up the chain of calls looking for private functions with the given name.
Because of this, when you use a quoted string as the routine to invoke, the name you give must be that of a public routine — a routine must have its own .m or .p or .mdl or .slx file (or be built in).
This restriction only applies when you use a quoted string for the routine. If you use @ and the name of a private routine then that would work (provided the routine is in scope.)
Moral of the story is to not use quoted strings as the routine name.
  1 Comment
Matthew Charles
Matthew Charles on 8 Mar 2022
Hi Walter, the name of the file is indeed: noik.m
however in the command window when I use @ as you have suggested. I got the following output:
Unrecognized function or variable 'emul'.
So I am confused as to why the function is not running. Any assistance will be greatly appreciated

Sign in to comment.


Image Analyst
Image Analyst on 8 Mar 2022
You should not have a file noik.m and have this be the first line of code:
function dh_s = emul(t,hs)
You should call that emul.m. Then your noik code should call emul inside of it. emul.m should be in the current folder or on the serach path.
What does this say
>> which -all emul
  2 Comments
Matthew Charles
Matthew Charles on 8 Mar 2022
When I used which -all emul, I got the response: /MATLAB Drive/emul.m
Thus, after renaming the file to emul.m and using the same code above, I attempted to the run the code via the Command Window using this :
t = [0,180];
h0 = [0];
[t, hs] = ode45(@emul, t, h0);
However, I got the following failed response:
Not entirely sure what to do at this point, using the above code function
Steven Lord
Steven Lord on 8 Mar 2022
Move the constants you define in the file with the emul function into the emul function itself. Make sure the first executable line of that file is the line:
function dh_s = emul(t,hs)
You may have comments before that line, but no executable code before that function line. Save this file as emul.m. Now run your ode45 call as before.

Sign in to comment.

Categories

Find more on Electrophysiology in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!