Domain error. To compute complex results, make at least one input complex, e.g. 'power(complex(a),b)'.

8 次查看(过去 30 天)
Hi, Im getting the following error:
Domain error. To compute complex results, make at least one input complex, e.g. 'power(complex(a),b)'.
function y = fcn(u, Pm)
Cd = 1; %Discharge Coefficient (determined expermentally = actual mass flow/ideal mass flow)) [-]
P0 = 1.01*10^5; %Ambient pressure [Pa]
R = abs(287.1); %Gas constant [J/(kg*K)]
T0 = abs(293.15); %Atmospheric temp [K]
gamma = 1.4; %exponent [-]
q = (Cd*u*P0)/(sqrt(R*T0));
w = (Pm/P0)^(1/gamma);
e = (2*gamma)/(gamma-1);
f = (1.4-1)/1.4;
r = 1-(Pm/P0);
r = r^f;
x6 = q*w*(e*r)^(0.5);
y = x6;
Could anyone please help me? I do not require a complex solution (as far as I know, it should be just a number) and i've tried a lot: complex() and abs() (to try to tell matlab that it is a positive double).
thank you so much.
  4 个评论
Torsten
Torsten 2022-9-16
Pm is not, cannot and will not be a negative double
Might be. Then Pm becomes greater than P0 during the solution process which makes r negative.
Line 14 is r = r^f;
(Which works if I replace 'f' with a 1 but doesn't work when I replace it with 0.5 for example. (??)
Yes, r seems to become negative. Thus r^f becomes complex for non-integers f.
Mars de Bruin
Mars de Bruin 2022-9-16
you are an absolute legend. thank you so much.
I just had to look further than line 14 and actually see what could give negative values (like you said).
replacing r = 1-(Pm/P0); with r = abs(1-(Pm/P0)); and that worked!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by