How can I simplify this expression using "abs" function?
Show older comments
8 Comments
Dyuman Joshi
on 20 Nov 2023
What have you tried yet?
Sathish
on 20 Nov 2023
Sathish
on 20 Nov 2023
Star Strider
on 20 Nov 2023
Sathish
on 20 Nov 2023
Dyuman Joshi
on 20 Nov 2023
Edited: Dyuman Joshi
on 20 Nov 2023
Unfortunately (for you), MATLAB does not seem to be able to simplify this expression significantly beyond a particular point, see below.
WolframAlpha gives a weird-ish output (I can't recognize what the symbols similar to # are supposed to be) - https://www.wolframalpha.com/input?i=sum+abs%28k%2F6+-+n%2F6+%2B+k%5E2%2F2+%2B+k%5E3%2F3+-+n%5E2%2F2+-+n%5E3%2F3+%2B+%28k*%282*k+%2B+1%29*%28k+%2B+1%29%29%2F6%29%2C+k%3D1+to+n-1
You could try using MAPLE and see what output it gives.
It is also worth noting that not all symbolic expression can be simplified.
syms n k
A = (1/6)*(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k);
B = (1/6)*(k*(k+1)*(2*k+1));
C = symsum((abs(A-B)),k,1,n-1)
simplify(C, 'Steps', 100)
simplify(C, 'Steps', 200)
Sathish
on 20 Nov 2023
Walter Roberson
on 20 Nov 2023
I think in the Wolfram output that the # stand in for the variable whose value has to be found to make the expression zero
Answers (2)
This seems to work —
syms n k
Expr = 7/6 * symsum((2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^3 - k)-(k*(k+1)*(2*k+1))/6, k, 1, n-1)
Expr = simplify(Expr, 500)
.
5 Comments
Dyuman Joshi
on 20 Nov 2023
@Star Strider, there is an absolute sign missing in your code.
Sathish
on 20 Nov 2023
I thought the ‘|’ were 1.
Edited version —
syms n k
Expr = abs(1/6 * symsum((2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^3 - k)-(k*(k+1)*(2*k+1))/6, k, 1, n-1))
Expr = simplify(Expr, 500)
Added abs call.
.
Dyuman Joshi
on 20 Nov 2023
The abs() call is inside the symsum() call.
Star Strider
on 20 Nov 2023
Edited: Star Strider
on 20 Nov 2023
Edited —
syms n k
Expr = symsum(abs((2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k)/6-(k*(k+1)*(2*k+1))/6), k, 1, n-1)
Expr = simplify(Expr, 400)
.
You must determine the value for k0 where the expression
2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1)
changes sign from positive to negative. Then you can add
1/6*(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1))
from k = 1 to k = floor(k0) and add
-1/6*(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1)))
from k = floor(k0)+1 to k = n-1.
syms n k
p = simplify(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1))
s = solve(p,k,'MaxDegree',3)
result = simplify(1/6*symsum(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1),k,1,floor(s(1)))-...
1/6*symsum(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k - k*(k+1)*(2*k+1),k,floor(s(1))+1,n-1))
subs(result,n,13)
k = 1:12;
n = 13;
expr = 1/6*abs(2*n^3 + 3*n^2 + n - 2*k.^3 - 3*k.^2 - k - k.*(k+1).*(2*k+1))
sum(expr)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



