How to create a symbolic variable at special range.

I would like to create the symbolic variable 'x', which belongs to subspace [0. , 1.] of 'real 1d space'. I found that, "x=sym('x','real')" but it is not general as I would like "x=sym('x','[a, b]')", where 'a' and 'b' are real numbers with constrain ' a <= b '. Thanks.

Réponses (2)

hi Samouil,
try
assume(x,'positive');
assume(1-x,'positive');
hope this can help :)
Symbolic computations do not check constraints in some (common) operations, so although you could use assume() to add the constraint, there are more robust ways.
What you can do instead in MuPAD is to use Dom::Interval . This will have to be done at the MuPAD level, as this interface has not been exported to MATLAB. For example,
x = feval(symengine,'Dom::Interval', a, b);

3 commentaires

Samouil
Samouil le 21 Sep 2011
I try it, but I think dose not work.
Think that you have the parameter 'x,y,z' as '0.<=x,y,z<=1.', and the function :
a = y/(1-x);
b = z/(1-x);
f = simplify(a/(1-b))
the result is -y/(x+z-1).
If I do that 'x = feval(symengine,'Dom::Interval', a, b);' I get as result 'Dom::Interval(0, Inf) union Dom::Interval(-Inf, 0)' ????
Also I am looking for this particular question which is defining a symbolic variable in an interval(range). I want to make a plot for f(t) = exp(t) for some range such as 0<t<10.
You would not do that by putting assumptions on t. You would do something like
syms t
f(t) = exp(t)
fplot(f, [eps(realmin) 10*(1-eps)])
If it was especially important that you reach arbitrarily close to the limits without being at the limits, then use piecewise:
syms t
f(t) = piecewise(0 < t & t < 10, exp(t)); %no otherwise close implies undefined
fplot(f, [0 10])

Connectez-vous pour commenter.

Tags

Question posée :

le 20 Sep 2011

Commenté :

le 18 Mai 2020

Community Treasure Hunt

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

Start Hunting!

Translated by