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

조회 수: 41 (최근 30일)
%% 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

답변 (2개)

Walter Roberson
Walter Roberson 2022년 3월 7일
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
Matthew Charles
Matthew Charles 2022년 3월 8일
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

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2022년 3월 8일
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
Matthew Charles
Matthew Charles 2022년 3월 8일
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 2022년 3월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by