Piecewise function using sign
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I'm trying to solve a schrodinger equation for a particle in an asymmetrical potential well, I found a way to do it with Chebfun, but I fail to define the piecewise potential.
The potential is:
- For x smaller than 0, V(x)=inf
- For x in [0,a), V(x)=0
- For x in (a,b], V(x)=-V0
- For x larger than b, V(x)=inf
I'm trying to define V in a similar way to this;
x = chebfun('x',[-a,a+b]);
V = 80*(sign(x+1)-0.8*sign(x-0.9));
Is this possible with sign for a 4-piece function?
Réponses (1)
Walter Roberson
le 24 Jan 2018
0 votes
the inf makes this difficult. For finite values you can take (condition)*value which will be 0*value = 0 for finite values when the condition is false, but when value is infinite that is 0*inf which is NaN, and the NaN poisons everything else.
You can get at inf for a condition by taking 1/(~condition) to get 1/0 when the condition is true.
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!