How can I simplify this expression using "abs" function?

8 Kommentare

What have you tried yet?
>> syms n k
>> A = (1/6)*(2*n^3 + 3*n^2 + n - 2*k^3 - 3*k^2 - k)
A =
- k^3/3 - k^2/2 - k/6 + n^3/3 + n^2/2 + n/6
>> B = (1/6)*(k*(k+1)*(2*k+1))
B =
(k*(2*k + 1)*(k + 1))/6
>> C = symsum((abs(A-B)),k,1,n-1)
C =
symsum(abs(k/6 - n/6 + k^2/2 + k^3/3 - n^2/2 - n^3/3 + (k*(2*k + 1)*(k + 1))/6), k, 1, n - 1)
I want this expression to be simplified.
I am not certain what you want to do. Using symsum and simplify (allowing 500 iterations) worked when I tried it.
It is working when we give values of 'n' and 'k'.
But I am trying to get simplified expression with variable 'n' only.
For example:
>> syms n k
>> A = k^2
A =
k^2
>> B = n^2
B =
n^2
>> C = symsum((abs(A-B)),k,1,n-1)
C =
n^2*(n - 1) - (n*(2*n - 1)*(n - 1))/6
Unfortunately (for you), MATLAB does not seem to be able to simplify this expression significantly beyond a particular point, see below.
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)
C = 
simplify(C, 'Steps', 100)
ans = 
simplify(C, 'Steps', 200)
ans = 
Thank you for your suggestions.
I think in the Wolfram output that the # stand in for the variable whose value has to be found to make the expression zero

Melden Sie sich an, um zu kommentieren.

Antworten (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 = 
Expr = simplify(Expr, 500)
Expr = 
.

5 Kommentare

@Star Strider, there is an absolute sign missing in your code.
Yes. abs( ) is missing.
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 = 
Expr = simplify(Expr, 500)
Expr = 
Added abs call.
.
The abs() call is inside the symsum() call.
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 = 
Expr = simplify(Expr, 400)
Expr = 
.

Melden Sie sich an, um zu kommentieren.

Torsten
Torsten am 20 Nov. 2023
Bearbeitet: Torsten am 20 Nov. 2023
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))
p = 
s = solve(p,k,'MaxDegree',3)
s = 
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))
result = 
subs(result,n,13)
ans = 
6444
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))
expr = 1×12
817 809 791 759 709 637 539 411 249 49 193 481
sum(expr)
ans = 6444

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2015a

Tags

Gefragt:

am 20 Nov. 2023

Bearbeitet:

am 20 Nov. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by