Not auto change sec(x) to 1/cos(x)?
1 回表示 (過去 30 日間)
古いコメントを表示
Is there any setting anywhere that prevents symbolic mathematics package from converting sec(x) and csc(x) to their sine/cosine counterparts? Trying to auto-generate a derivative/antiderivative assignment for my calc kids, and they "know" the derivatives/antiderivatives as secs and tans, not necessarily as their sine/cosine equivalents. For example
syms x; sec(x)^2
I want it to just have sec(x)^2 instead. Any ideas except just converting everything to symbolic (like the trick when you want pi to not be it's numerical equivalent)?
Thanks
0 件のコメント
採用された回答
Dyuman Joshi
2024 年 2 月 22 日
移動済み: Dyuman Joshi
2024 年 2 月 22 日
Unfortunately, that is not possible.
The symbolic engine directly evaluates the function sec() to 1/cos() (and csc() to 1/sin()), see - https://in.mathworks.com/matlabcentral/answers/366337-matlab-symbolic-toolbox-deactivate-automatic-simplification#comment_3073193
2 件のコメント
その他の回答 (2 件)
Ayush Modi
2024 年 2 月 20 日
編集済み: the cyclist
2024 年 2 月 22 日
Hi Paul,
MATLAB tends to automatically simplify trigonometric expressions to "sin", "cos", or "tan" where possible. There are no settings to avoid it. However as a work around, you can use strrep function to replace the output with the desired strings.
syms x;
expr = sec(x)^2
% Convert the expression to a string
exprStr = char(expr);
% Replace '1/cos' with 'sec' in the string
exprStr = strrep(exprStr, '1/cos', 'sec')
Note - This will not prevent the simplification of expression by MATLAB.
John D'Errico
2024 年 2 月 22 日
編集済み: John D'Errico
2024 年 2 月 22 日
The problem is, which form is simpler? Simple in your eyes need not always be simple in the "eyes" of your computer.
The point is, the simplification tool needs to make a decision, and that decision may not be your preference. Even if you told it to allow all 6 trig functions, there would be many fairly simple choices it could make.
syms theta
X = sec(theta)^2
And that may seem simple to you, or not. It was the choice made by default, to use sin and cos where possible. But how about this one?
simplify(X,1000)
In my eyes, that seems pretty simple! But there are so many alternatives one could choose. A small subset is seen here:
simplify(X,'steps',100,'all',true)
Another option is to use rewrite:
rewrite(X,'sec')
And rewrite sometimes works, but 'sec' was not an option.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!