symbolic integration depends on different equivalent forms of function

I performed the following equaivalent symbolic integrations:
syms x y
A = int(x+y,x);
A_ = expand(A); % just expanded (equaivalent) form of A
B = expand(int(A,y))
B_ = expand(int(A_,y))
with the following results:
A =
(x*(x + 2*y))/2
A_ =
x^2/2 + y*x
B =
x^3/8 + (x^2*y)/2 + (x*y^2)/2
B_ =
(x^2*y)/2 + (x*y^2)/2
I expect B equal to B_, but there is a misterious additional term x^3/8 at B ??!!
Is that a bug???

回答 (2 件)

Torsten
Torsten 2022 年 7 月 15 日
The difference is a usual "constant of integration".
If you differentiate both B and B_ with respect to y and then with respect to x, you'll arrive at the expression x+y in both cases:
syms x y
B_ = (x^2*y)/2 + (x*y^2)/2;
B = x^3/8 + (x^2*y)/2 + (x*y^2)/2;
A_ = diff(B_,y);
A = diff(B,y);
expr1 = diff(A_,x)
expr1 = 
expr2 = diff(A,x)
expr2 = 

7 件のコメント

Michal
Michal 2022 年 7 月 15 日
編集済み: Michal 2022 年 7 月 15 日
Why this effect of integration constant depends on presence of expand() function at
A_ = expand(A)
???
Torsten
Torsten 2022 年 7 月 15 日
Because deep in the MATLAB rules for symbolic integration, the sum of two polynomial expressions (x^2/2 + y*x) is integrated differently from a single product polynomial ( (x*(x + 2*y))/2 ).
In short: Only the developers know the answer.
Michal
Michal 2022 年 7 月 15 日
Yes, and this is the problem... Two different results of integration for two mathematically equivalent SIMPLE expressions!
The fact that backward double differentiation produces the same result is irrelevant.
Torsten
Torsten 2022 年 7 月 15 日
編集済み: Torsten 2022 年 7 月 15 日
The fact that backward double differentiation produces the same result is irrelevant.
No. You try to determine a function for which
d/dx (d/dy(f(x,y)) = x+y.
There are infinitely many functions for which this is true.
E.g. if you want to determine a function with d/dx (d/dy (f(x,y)) = 0, every function of the form
f(x,y) = f1(x) + f2(y)
is "correct" .
If you want to make the result of integration unique, you must fix f(x,y) on a 1d-curve in the x-y-plane (which is not parallel to one of the coordinate axes, I guess).
Michal
Michal 2022 年 7 月 15 日
編集済み: Michal 2022 年 7 月 15 日
The main point of my question is the fact, that
int(int(x+y,x),y)
is not same as
int(expand(int(x+y,x),y))
which is really strange!!! That is all ... But, you are right that: Only the developers know the answer.:)
I'm not surprised that
int((x*(x + 2*y))/2,y)
gives a result different from
int(x^2/2 + y*x,y).
See
syms x
int((x-1)^2,x)
ans = 
compared to
int(x^2-2*x+1,x)
ans = 
Paul
Paul 2022 年 7 月 15 日
編集済み: Paul 2022 年 7 月 15 日
I'm not surprised either. I've seen cases where int() couldn't find a solution unless the integrand was manipulated using simplify, expand, etc. Here is an example from this Question
syms t
assume(t, "real")
f1 = 3*t-t*t*t;
f2 = 3*t*t;
f = [f1, f2];
df = diff(f, t);
a = 0;
b = 1;
normDf = sqrt(df(1)*df(1)+df(2)*df(2));
int(normDf,t,a,b) % no solution
ans = 
normDf = simplify(normDf)
normDf = 
int(normDf, t, a, b) % easy
ans = 
4

サインインしてコメントする。

Michal
Michal 2022 年 7 月 16 日
編集済み: Michal 2022 年 7 月 16 日
Simple solution to avoid integration constant effect:
int(f(x),x,0,x)

4 件のコメント

Torsten
Torsten 2022 年 7 月 16 日
This assumes that you want a special antiderivative F of f, namely the antiderivative with F(0) = 0. As I wrote, if in 1d, you fix the antiderivative in one point and in 2d, you fix the antiderivative on a curve, you get a unique solution for d/dx (d/dy (f(x,y))) = x+y.
Michal
Michal 2022 年 7 月 16 日
int(int(f(x,y),y,0,y),x,0,x)
reliable produce results without misterious integration constant terms and does not depends on any pre-processing steps (like expand, simplify, etc.)
Torsten
Torsten 2022 年 7 月 16 日
編集済み: Torsten 2022 年 7 月 16 日
syms x y
A1 = int(sin(x)+sin(y),x,0,x);
B1 = int(A1,y,0,y)
B1 = 
simplify(B1)
ans = 
A2 = int(sin(x)+sin(y),x);
B2 = int(A2,y)
B2 = 
You see, the integration constant of your method is x+y.
All I want to say is:
Each integration gives its individual integration constant. For the differential equation
d/dx (d/dy(F(x,y))) = x+y
e.g., the "integration constants" are functions of the form
G(x,y) = g1(x) + g2(y)
unless you fix F on a curve in the (x,y) plane (not parallel to one of he coordiante axes).
Some integration constants look more plausible, others less.
And now I will be quiet and you can have "the last word", if you want.
Michal
Michal 2022 年 7 月 17 日
Well... You are right!

サインインしてコメントする。

カテゴリ

製品

リリース

R2022a

質問済み:

2022 年 7 月 15 日

コメント済み:

2022 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by