简体   繁体   English

Matlab分母中复杂功能与重糖苷的积分

[英]integration of complicated function with heaviside in denominator in Matlab

I want to evaluate the following expression: 我想评估以下表达式:

表达

I have used the Matlab int command, but for unknown reason, complex number and pi are parts of Matlab's answer. 我使用过Matlab int命令,但是由于未知原因,复数和pi是Matlab答案的一部分。

syms x;
q = int(1/((9*(1 - x^2)^(1/2)*(heaviside(x - 1) - heaviside(x + 1)))/5 + 2*(4 - x^2)^(1/2)),-2,2)

It is giving me this pretty complex answer: 它给了我这个相当复杂的答案:

(68*pi)/19 - (450*pi*957^(1/2))/6061 - (957^(1/2)*log(5700)*225*i)/6061 + (957^(1/2)log(3^(1/2)((19*319^(1/2))/2700 - (3*19^(1/2))/100 + (6061^(1/2)*i)/300 + (19*i)/300))*225*i)/6061 - (957^(1/2)log(-3^(1/2)((3*19^(1/2))/100 + (19*319^(1/2))/2700 + (6061^(1/2)*i)/300 - (19*i)/300))*225*i)/6061 + (957^(1/2)*log(10*57^(1/2))*450*i)/6061 - (19^(1/2)*243^(1/2)*6061^(1/2)*log((3^(1/2)*i + (19^(1/2)243^(1/2)(6061^(1/2)/19 + 4))/243)/(6061^(1/2)/19 + 1))*25*i)/115159 + (19^(1/2)*243^(1/2)*6061^(1/2)*log(-(3^(1/2)*i - (19^(1/2)243^(1/2)(6061^(1/2)/19 - 4))/243)/(6061^(1/2)/19 - 1))*25*i)/115159

where as the answer should be between 1 and 10 real only (not complex) if my research model is right. 如果我的研究模型正确,那么答案应该仅在1到10个实数之间(不复杂)。

Can you give me any suggestions, any command, or point anything I am doing wrong in matlab that is giving this complex answer. 您能给我任何建议,任何命令还是指出我在matlab中做错的任何事情吗?

You are worrying about the wrong thing. 您正在担心错误的事情。 The result you are getting is in the range [1 10]. 你所得到的结果在范围[1 10]。 The complex parts will cancel each others out. 复杂的部分将互相抵消。

If I evaluate your code: 如果我评估您的代码:

syms x;
q = int(1/((9*(1 - x^2)^(1/2)*(heaviside(x - 1) - heaviside(x + 1)))/5 + 2*(4 - x^2)^(1/2)),-2,2)

I obtain a different expression for q than you: 我得到的q表达式与您不同:

q =
(68*pi)/19 - (45*pi*300^(1/2)*319^(1/2))/6061 - (45*300^(1/2)*319^(1/2)*i*log(243*19^(1/2)*319^(1/2) - 4617))/6061 + (45*300^(1/2)*319^(1/2)*i*log(243*19^(1/2)*319^(1/2) + 4617))/6061 - (45*300^(1/2)*319^(1/2)*i*log(300*19^(1/2)*319^(1/2) - 5700))/6061 + (45*300^(1/2)*319^(1/2)*i*log(300*19^(1/2)*319^(1/2) + 5700))/6061 + (45*300^(1/2)*319^(1/2)*i*log(19*300^(1/2)*319^(1/2) - 19*19^(1/2)*300^(1/2)))/6061 - (45*300^(1/2)*319^(1/2)*i*log(19*19^(1/2)*300^(1/2) + 19*300^(1/2)*319^(1/2)))/6061 - (45*300^(1/2)*319^(1/2)*i*log(- 76*19^(1/2)*243^(1/2) - 19*243^(1/2)*319^(1/2) - 4617*3^(1/2)*i))/12122 + (45*300^(1/2)*319^(1/2)*i*log(19*243^(1/2)*319^(1/2) - 76*19^(1/2)*243^(1/2) - 4617*3^(1/2)*i))/12122 + (45*300^(1/2)*319^(1/2)*i*log(76*19^(1/2)*243^(1/2) - 19*243^(1/2)*319^(1/2) + 4617*3^(1/2)*i))/12122 - (45*300^(1/2)*319^(1/2)*i*log(76*19^(1/2)*243^(1/2) + 19*243^(1/2)*319^(1/2) + 4617*3^(1/2)*i))/12122

However, if I evaluate it in an old fashion (this works on Matlab R2009a): 但是,如果我以旧方式评估它(这在Matlab R2009a上有效):

>> q.eval
ans =
  1.883829527329203 - 0.000000000000004i

You should notice that the imaginary part is next to nothing. 您应注意,虚部几乎没有。 This is just a residue of calculation error. 这只是计算错误的残余。 You cannot expect more than 15 digits precision when using 64 bits floating point number representation (matlab double format). 使用64位浮点数表示法(matlab double精度格式)时,您不能期望超过15位的精度。 Expect even less if it is the result of long calculations (the error may grow with the number of computations). 如果这是长时间计算的结果,则期望值更低(误差可能会随着计算次数的增加而增加)。

In this case, you can safely discard a value of 0.000000000000004 and assimilate it to 0 . 在这种情况下,您可以放心地放弃一个值0.000000000000004并将其同化为0 Which means that your integral evaluated a real number. 这意味着您的积分求出了一个数。

Now I don't know what your research conclude, but if you are positively certain that the result has to be real , then you can take only the real part of the expression: 现在我不知道您的研究结论是什么,但是如果您肯定确定结果必须实数 ,那么您只能采用表达式的部:

>> q.real.eval
ans =
   1.883829527329203

Thanks to Horchler's comment, a better way to evaluate the value of the integral is to directly cast it into a double precision number : 感谢Horchler的评论,评估积分值的更好方法是将其直接转换为double精度数:

>> double(q)
ans =
  1.883829527329202 - 0.000000000000000i

Apparently, Matlab have improved the conversion to double (and let the old q.eval method get deprecated) because the residual error on the imaginary part is smaller yet. 显然,Matlab已将转换改进为两倍(不赞成使用旧的q.eval方法),因为虚部的残差较小。

If as above you only want the real part of the result, use the function real in conjunction with double , which still give the same result: 如果如上所述,您只想要结果的实数部分,则将real函数与double结合使用,仍然可以得到相同的结果:

>> double(real(q))
ans =
   1.883829527329202

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM