From: Stefano Pasetto on
Dear Mathematica experts:

is there a possibility to implement a constraint in NDSolve?

Suppose I want to solve



NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3, x[0] == y[0]
== 1}, {x, y}, {t, 20}]



But I want that the solutions satisfied the inequality x[t]>0 for every t
(because it represent a physical quantity that has no meaning to be
negative), i.e., and when it becomes =0 it has to stay zero. I've tried
something like



x[t_]:=If[x[t]>0,x[t],0]



in the definition of x or y but it does not make sense. Somehow, I'd need to
change the solution of the system when the solution itself become negative.

ThankX for the help, :-)

Best regards

Stefano Pasetto

From: dh on


Hi Stefano,

I think you are attacking your problem the wrong way. If the DE says

that the solution becomes negative then you can not simply request that

is is zero. In your case, the model does obviously not mirror the

physical system.

Now, if you can live with the imperfection of you model, you may simply

force the solution not to be nagative by taking the Max[0, solution].

But it will be better if you look for a better model that suits the

physical system.

Daniel



Stefano Pasetto wrote:

> Dear Mathematica experts:

>

> is there a possibility to implement a constraint in NDSolve?

>

> Suppose I want to solve

>

>

>

> NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3, x[0] == y[0]

> == 1}, {x, y}, {t, 20}]

>

>

>

> But I want that the solutions satisfied the inequality x[t]>0 for every t

> (because it represent a physical quantity that has no meaning to be

> negative), i.e., and when it becomes =0 it has to stay zero. I've tried

> something like

>

>

>

> x[t_]:=If[x[t]>0,x[t],0]

>

>

>

> in the definition of x or y but it does not make sense. Somehow, I'd need to

> change the solution of the system when the solution itself become negative.

>

> ThankX for the help, :-)

>

> Best regards

>

> Stefano Pasetto

>



From: Alexei Boulbitch on
Dear Stefano,

one way to cope with such a constraint would be to introduce a non-linear replacement of the variables
that automatically accounts for the property you need.

It is like in theory of magnetism or liquid crystals people introduce
a replacement of variables in the equation for order parameters, if they want to neglect the order parameter variation
in absolute value. Typically they go to spherical coordinates of the order parameter, rather than to their Cartesian
coordinates). If needed, you may have a look into the books:
Landau, L. D. & Lifshitz, E. M. Electrodynamics of Continuous Media (Elswier Butterworth-Heinemann, Oxford, 2004) and
de Gennes, P. G. The Physics of Liquid Crystals (Oxford University Press, London, 1974).

In particular, in your problem the best replacement would be the one most closely related to the physical sense of your
variable x=x(t). However, if this physical sense-related transformation is not clear, why not to introduce x=z[t]^2?
Or x=Exp[-z[t]] ? You should then formulate your system of equation in terms of y[t] and z[t].
Like this you make sure that your variable is positive everywhere. The price is the additional non-linearity introduced,
but since your solution is anyway numeric this may be not that bad.

Have success, Alexei




Dear Mathematica experts:

is there a possibility to implement a constraint in NDSolve?

Suppose I want to solve



NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == 2 x[t] - y[t]^3, x[0] == y[0]
== 1}, {x, y}, {t, 20}]



But I want that the solutions satisfied the inequality x[t]>0 for every t
(because it represent a physical quantity that has no meaning to be
negative), i.e., and when it becomes =0 it has to stay zero. I've tried
something like



x[t_]:=If[x[t]>0,x[t],0]



in the definition of x or y but it does not make sense. Somehow, I'd need to
change the solution of the system when the solution itself become negative.

ThankX for the help, :-)

Best regards

Stefano Pasetto

--
Alexei Boulbitch, Dr., habil.
Senior Scientist

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern
Luxembourg

Phone: +352 2454 2566
Fax: +352 2454 3566

Website: www.iee.lu

This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.