# Evaluating a symbolic heaviside function using subs at points where disconuities are located

2 visualizaciones (últimos 30 días)
Aleem Andrew el 26 de Oct. de 2020
Comentada: Aleem Andrew el 30 de Oct. de 2020
When trying to evaluate a symbolic function, Matlab outputs 'Nan' when it encounters discontinuities.
syms x
f = 22*heaviside(x - 5)*(x - 5) - 20*heaviside(x - 2)*(x - 2) - 20*heaviside(x - 3)*(x - 3) - 10*heaviside(x - 1)*(x - 1) + 28*x*heaviside(x)
fplot(diff(f,1),[-2 6])
x = [1 2 3 4]
subs(diff(f,1))
The output is
ans =
[ NaN, NaN, NaN, -22]
However, I would like to know the value at 1+,2+,3+ and so on so the desired output is [18 -2 -22 -22]. Is there a way to deal with disconituities by outputting the function value as x approaches a particular value from the left or right without typing for example subs(diff(f,1.0001)) or subs(diff(f,1+eps))?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Shubham Rawat el 30 de Oct. de 2020
Hi Aleem,
You may use limit function for the discontinuities:
syms x
f = 22*heaviside(x - 5)*(x - 5) - 20*heaviside(x - 2)*(x - 2) - 20*heaviside(x - 3)*(x - 3) - 10*heaviside(x - 1)*(x - 1) + 28*x*heaviside(x)
g = diff(f,1); % g is differentiation of f
limit(g,x,1,'right') % this gives the right limit of function g at x = 1
You may refer to the limit documentation page for further reference:
https://www.mathworks.com/help/symbolic/limit.html
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Aleem Andrew el 30 de Oct. de 2020

Iniciar sesión para comentar.

### Categorías

Más información sobre Assumptions en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by