why i get 'complex double' type?

93 次查看(过去 30 天)
Hi, i have below code. When run it i get kro as complex double.
Do you have any idea about why it is complex number, and how i can fix it.
By the way krw is not complex, just kro is complex.
thanx
swi=0.328; sor=0.205;
sw=linspace(swi,1-sor,100);
swd=(sw-swi)./(1-swi-sor);
kro=(1-swd).^2.56;
krw=0.78*(swd).^3.72;

采纳的回答

Walter Roberson
Walter Roberson 2021-7-21
Although algebraically the maximum swd value should be 1 exactly, because of round-off error it turns out to be just slightly greater than 1. Then 1 minus that can be just slightly negative. Negative raised to a fraction is complex.
Take min(swd, 1)
  3 个评论
Walter Roberson
Walter Roberson 2021-7-21
swd = min(swd, 1);
means the same thing as
for K = 1 : numel(swd)
if swd(K) > 1; swd(K) = 1; end
end
That is, at any time, you take the minimum of what is in swd, compared to the constant 1. Any swd entry that is greater than 1 will be reduced to 1.
ali yaman
ali yaman 2021-7-22
i got it. Thank you very much

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by