Borrar filtros
Borrar filtros

Should simplify() Work Better on Symbolic Expressions Involving heavisde() with an Ineteger Argument?

1 visualización (últimos 30 días)
I was playing around with what I thought was a simple problem but turned out to not be.
Let x(n) be the input to a discrete-time linear system with impulse response h(n)
syms n integer
assumeAlso(n >= 0);
sympref('HeavisideAtOrigin',1);
x(n) = sym(1)*heaviside(n);
h(n) = 0.9^n*heaviside(n-1);
The output of the system can be determined via convolution
syms k ineteger
assume(k >= 0);
y1(n) = simplify(symsum(x(k)*h(n-k),k,0,n))
y1(n) = 
I'm surprised that the summand includes that product of heaviside(), insofar as Matlab knows that, under the given assumptions,
isAlways(heaviside(n-k-1)*heaviside(k)==heaviside(n-k-1))
ans = logical
1
So we can remove the heaviside(k) from the summand by hand
y1a(n) = simplify(symsum((sym(9)/sym(10))^(n-k)*heaviside(n-k-1),k,0,n))
y1a(n) = 
Still no closed-form solution. Is it too much to expect of symsum() and simplify() that the solution can also be written as
y2(n) = simplify(symsum((sym(9)/sym(10))^(n-k),k,0,n-1))
y2(n) = 
We could also get the solution as follows
x(n) = sym(1);
z(n) = 0.9^(n+1); % shift the impulse response left by one
y3(n) = symsum(x(k)*z(n-k),k,0,n);
y3(n) = simplify(y3);
y3(n) = simplify(simplify(y3(n-1))*heaviside(n-1)) % shift result right by one
y3(n) = 
Again, the inclusion of heaviside() in the solution is superfluous, but maybe it's too much for simplify to realize that?
The simplest answer comes from ztrans/iztrans
x(n) = sym(1)*heaviside(n);
h(n) = 0.9^n*heaviside(n-1);
syms z
y4(n) = iztrans(ztrans(x(n),n,z)*ztrans(h(n),n,z),z,n)
y4(n) = 
I realize that "simpler" is often in the eye of the beholder, but maybe simplify() could do better in some of these case? IDK.
I also noticed an odd result with heaviside()
heaviside(n+2) % simplest result under assumptions on n
ans = 
1
heaviside(n+1) % simplest result under assumptions on n
ans = 
1
heaviside(n) % correct, but not simplest result under assumptions on n AND sympref
ans = 
Hmm, now I'm wondering how that isAlways() expression above evaluated to true.
Of course, no result here is in error. Just wondering if it's reasonable to expect the Symbolic Math Toolbox to do just a bit better in these cases (except y4, of course).

Respuestas (1)

Dheeraj
Dheeraj el 8 de En. de 2024
Hi,
I understand that you are trying to simply your expression with discrete values with Symbolic Math Toolbox and you are not getting results up to your expectations.
The simplification capabilities of symbolic computation tools, such as the Symbolic Math Toolbox in MATLAB, can sometimes be limited, especially when dealing with specific conditions and assumptions, but is evolving with every release.
The convolution you're dealing with involves a product of heaviside functions. Simplifying such expressions can be intricate, and the results may not always match your expectations. The behaviour of simplify can be influenced by the assumptions you provide, and sometimes it may not automatically simplify expressions as much as desired.
The isAlways function might consider the piecewise definition of heaviside rather than the specific assumptions as “heaviside” is a piecewise function whose behaviour depends on assumptions.
Manual intervention is needed sometimes like in y3 example when dealing with shifted sequences.
Symbolic computation tools aim to provide powerful simplification capabilities, there are cases where manual intervention or alternative approaches may be needed. The tool's choices in simplification can be influenced by the complexity of the expressions and the provided assumptions.
For better understanding of the toolbox, you could have a look at the below MATLAB’s documentation.
Hope this helps!

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by