Assumption on another symbolic Variable affecting a previous assumption

Why is the assumption I made being changed by the next assumption I do on another variable ?
The assumpitons on Phi_geod and Phi_dot_geod are being changed by the assumptions on the variables lambda_geod and lambda_dot_geod.
Code:
syms Phi_geod(t) lambda_geod(t)
syms Phi_dot_geod(t) lambda_dot_geod(t)
assumptions(Phi_geod)
ans = Empty sym: 1-by-0
assume(Phi_geod(t),"real");
assumptions(Phi_geod)
ans = 
assume(lambda_geod(t),"real");
assumptions(Phi_geod)
ans = 
assume(Phi_dot_geod(t),"real");
assume(lambda_dot_geod(t),"real");
assumptions(Phi_geod)
ans = 

 Réponse acceptée

Because assume over-writes assumptions.
From the Tips section in the documentation page -
"assume removes any assumptions previously set on the symbolic variables. To retain previous assumptions while adding an assumption, use assumeAlso."
As mentioned in the note above, you need to use assumeAlso, after using assume() the first time.
syms Phi_geod(t) lambda_geod(t)
syms Phi_dot_geod(t) lambda_dot_geod(t)
assumptions(Phi_geod)
ans = Empty sym: 1-by-0
assume(Phi_geod(t),"real");
assumptions(Phi_geod)
ans = 
assumeAlso(lambda_geod(t),"real");
assumptions(Phi_geod)
ans = 
assumeAlso(Phi_dot_geod(t),"real");
assumeAlso(lambda_dot_geod(t),"real");
ans = 
assumptions(Phi_geod)
ans = 

5 commentaires

Hi Dyuman,
I think that's a misreading of the Tip wrt to the "symbolic variables" the tip is referencing. In that context, the symbolic variables are referencing the variables in the input to the assume command.
For example:
syms x y
class(x), class(y)
ans = 'sym'
ans = 'sym'
assumptions
ans = Empty sym: 1-by-0
assume(x,'positive')
assumptions
ans = 
assume(y,'integer'); % doesn't change assumption on x
assumptions
ans = 
assume(x,'real'); % removes previous assumption on x, doesn't change assumption on y
assumptions
ans = 
However, assume() seems to work differently when the inputs are symfun, rather than sym
syms x(t) y(t)
class(x)
ans = 'symfun'
class(y)
ans = 'symfun'
assumptions % all assumptions cleared on x and y after call to syms
ans = Empty sym: 1-by-0
assume(x(t),'positive')
assumptions
ans = 
Here, adding an assumption on y(t), which I assume is treated as a symbolic expression by assume, does remove assumptions on x. i don't understand why that is the case.
assume(y(t),'integer'); % does change assumption on x?
assumptions
ans = 
That is because the symbolic functions are functions of the same symbolic variable - The assumptions are set on the independent variables, because the function is dependent on them as well.
((( This is not explicitly mentioned in the documentation, but is my understading, additionally, based on this statement in the tips section - "The toolbox does not support assumptions on symbolic functions. Set assumptions on symbolic variables and expressions instead." )))
Here, I have used a different independent variable to define y -
syms x(t) y(s)
class(x)
ans = 'symfun'
class(y)
ans = 'symfun'
assumptions
ans = Empty sym: 1-by-0
assume(x(t),'positive')
assumptions
ans = 
assume(y(s),'integer')
assumptions
ans = 
As you can see, the assumption on x(t) is not affected.
When you change the assumption w.r.t to independent variables, the assumptions on any depending variables/functions also gets cleared -
assume(t, 'integer')
assumptions
ans = 
I was wondering about exactly this, i.e., how y(t) is treated by assume(). I said "[y(t)] is treated as a symbolic expression", because I saw that symfun is not listed as an allowable input to assume, but y(t) is, or appears to be, an expression
syms y(t)
isSymType(y(t),'expression')
ans = logical
1
This works
assume(y(t),'positive')
z(t) = 2*y(t);assumptions
ans = 
isAlways(z(t)>0)
ans = logical
1
which suggests that y(t) is being treated as an expression.
But this throws an error
try
assume(y,'real')
catch ME
ME.message
end
ans = 'Assumptions on symbolic functions not supported. Make assumptions on symbolic variables and expressions instead.'
presumably because the class of y ( not y(t) ) is a symfun.
I suspect that your other observation about the interaction between the independent variable in the expression y(t) is really at the heart of this situation.
Based on the evidence, when the doc says: "assume removes any assumptions previously set on the symbolic variables."
perhaps it should say: "assume removes any assumptions previously set on the symbolic variables and removes assumptions previously set on any expressions that contain the symbolic variables"
Yes, the class of y is symfun and the class of y(t) is not symfun.
And yes, the statement should be more precise as you have stated.
syms y(t)
class(y)
ans = 'symfun'
class(y(t))
ans = 'sym'
try
assume(y(t),'real')
catch ME
ME.message
end
assumptions
ans = 
try
assume(y,'real')
catch ME
ME.message
end
ans = 'Assumptions on symbolic functions not supported. Make assumptions on symbolic variables and expressions instead.'
y(t) = t^2;
%returns the function definition
y
y(t) = 
%returns the expression
y(t)
ans = 
Thank you very much! This constructive discussion has made it very clear to me. Thank you for your help! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by