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

9 views (last 30 days)
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 Comments
Torsten
Torsten on 16 Sep 2022
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 on 16 Sep 2022
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!

Sign in to comment.

Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!