Because the plot command does not work? Matlab calculate improper integrals?
Afficher commentaires plus anciens
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
>>
Réponses (1)
Roger Stafford
le 12 Avr 2016
Modifié(e) : Roger Stafford
le 12 Avr 2016
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 commentaires
Ubaldo
le 20 Avr 2016
Roger Stafford
le 20 Avr 2016
@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
le 21 Avr 2016
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.
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!