How can I obtain the most simplified version of the symbolic solution of an equation that contains such functions as 'log' in a fractional and not decimal representation?
2 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2022-1-12
编辑: MathWorks Support Team
2022-4-15
Given is an equation that is sought to be symbolically solved in MATLAB using the Symbolic Math Toolbox, namely,
syms x
eqn = log(2*x)/log(3)==-1
It is known that the analytical solution of the latter equation is the following one,
res =
1/6
However, when using the function 'solve' from MATLAB and then the command 'simplify' with the Name-Value pair 'IgnoreAnalyticConstraints'-true, then 'log(3)' is firstly replaced by the fractional number '2473854946935173/2251799813685248' and as a result, the resulting expression appears still complex, namely,
>> res = simplify(solve(eqn,x,'IgnoreAnalyticConstraints',true))
res =
exp(-2473854946935173/2251799813685248)/2
MATLAB cannot simplify this expression further to '1/6' which is the expected solution.
How can I obtain the most simplified version of the symbolic solution of an equation that contains such functions as 'log' in a fractional and not decimal representation?
采纳的回答
MathWorks Support Team
2022-4-15
编辑:MathWorks Support Team
2022-4-15
In this case one needs to prevent MATLAB from expanding expression 'log(3)' to the aforementioned fractional number. To achieve this, please use an additional symbolic variable in the place of number 3, say 'y', solve the equation symbolically and substitute 'y' with 3 in the solution, namely,
syms x y
eqn = log(2*x)/log(y) == -1;
res = simplify(solve(eqn,x,'IgnoreAnalyticConstraints',true));
res = subs(res, y, 3);
This way the desirable result '1/6' can be obtained.
Another workaround is to declare the number 3 within function 'log' as symbolic, in which case the expression log(3) won't be expanded by MATLAB, see the following lines of code,
syms x
eqn = log(2*x)/log(sym(3))==-1
simplify(solve(eqn,x,'IgnoreAnalyticConstraints',true))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!