Because the plot command does not work? Matlab calculate improper integrals?
이전 댓글 표시
1) Because the plot command does not work?
2) Matlab calculate improper integrals?
3) How it sets the actual field in matlab?
The code that does not work as I would like is this:
clc
close all
clear all
format compact
syms x
y = (x-2).^(1/3);
I = int(y,x,[0,4])
(3*2^(1/3)*((-1)^(1/3) + 1))/2
figure
ezplot(y,[0,4])
I =
(3*2^(1/3)*((-1)^(1/3) + 1))/2
ans =
2.8348 + 1.6367i
>>
답변 (1개)
Roger Stafford
2016년 4월 12일
편집: Roger Stafford
2016년 4월 12일
The problem here is that (-1)^(1/3) has three different possible roots, namely: 1/2+1/2*sqrt(3)*1i, 1/2-1/2*sqrt(3)*1i, and -1. Take the cube of each of these and you will get -1 in all three cases. A similar thing is true for any negative quantity, as for example, (-27)^(1/3). Its three roots are: 3/2+3/2*sqrt(3)*1i, 3/2-3/2*sqrt(3)*1i), and -3. If matlab is confronted with an expression such as (-27)^(1/3), it will choose the first of these, 3/2+3/2*sqrt(3)*1i, and not -3. One way to force matlab to give you a negative real as an answer for x^(1/3) with negative real x, is sign(x)*(abs(x))^(1/3).
The output of your 'int' is correct if you interpret (-1)^(1/3) as being -1. That would make the answer zero, which is correct, assuming (x-2)^(1/3) is interpreted correctly for negative x. Therefore in your plot you should write:
y = sign(x-2).*(abs(x-2)).^(1/3);
and it will plot correctly, and make it clear from its symmetry that its integral should be zero.
Here is one possible explanation for matlab's choice for fractional powers of negative numbers. Suppose x is negative and real. Matlab can (and may actually) express x^(1/3) in terms of the logarithm function as follows:
x^(1/3) = exp(log(x^(1/3))) = exp(1/3*log(x))
Letting x = -27 and we would get
(-27)^(1/3) = exp(1/3*log(-27)) = exp(1/3*(log(27)+pi*1i))
= exp(log(27^(1/3))+1/3*pi*1i) = exp(log(3)+1/3*pi*1i)
= exp(log(3))*exp(1/3*pi*1i)
= 3*(cos(1/3*pi)+sin(1/3*pi)*1i)
= 3*(1/2+1/2*sqrt(3)*1i) = 3/2+3/2*sqrt(3)*1i
which is what matlab actually gets, not -3. A similar reasoning applies to other possible fractional powers of negative numbers.
댓글 수: 3
Ubaldo
2016년 4월 20일
Roger Stafford
2016년 4월 20일
@Ubaldo: In reference to your remark in (A): "2) Matlab is no longer suitable to work inside the numerical set R", what would you have matlab do with (-25)^(1/2)? Its two possible roots are both in the complex world. Once you introduce fractional powers, you inevitably encounter complex numbers. There is no way to remain always in the "set R". You will run into the same kinds of problems with Mathematica, since they also choose as a "principal" cube root of a negative number, a complex number with positive imaginary part.
Walter Roberson
2016년 4월 21일
You can use nthroot(-27, 3) to force using the real root (if one exists). There is also realpow(), reallog(), realsqrt()
If you work symbolically then you get all of the roots of polynomials -- though of course there are only exact solutions up to degree 4.
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!