Ask Your Question
1

Defining functions over symbolic domains

asked 2018-11-07 21:04:09 +0100

vaibhavkarve gravatar image

Is there a way to define a function that takes a value (say $x$) on the interval $[-L, L]$ and is zero everywhere else? I tried the following code but it doesn't work. It gives me an error. This is because piecewise only accepts real intervals. Is there an alternative way of defining this? I want to be able to integrate/differentiate such types of functions so my understanding is that I also cannot use def here.

L = var('L', domain = 'positive')
f = piecewise([((-oo, -L), 0), ([-L, L], x), ((L, oo), 0)])
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-11-08 17:48:17 +0100

eric_g gravatar image

A solution is to use the symbolic function unit_step:

sage: L = var('L', domain = 'positive')
sage: f(x) = unit_step(L+x)*unit_step(L-x)*x
sage: diff(f(x), x)
-x*dirac_delta(L - x)*unit_step(L + x) + x*dirac_delta(L + x)*unit_step(L - x) + unit_step(L + x)*unit_step(L - x)
sage: integrate(f(x), (x, 0, 3*L))
1/2*L^2
sage: integrate(f(x), (x, -3*L, 3*L))
0
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-07 21:04:09 +0100

Seen: 1,085 times

Last updated: Nov 08 '18