Not auto change sec(x) to 1/cos(x)?

조회 수: 1 (최근 30일)
Paul Dostert
Paul Dostert 2024년 1월 31일
편집: John D'Errico 2024년 2월 22일
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
ans = 
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

채택된 답변

Dyuman Joshi
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
Paul Dostert
Paul Dostert 2024년 2월 22일
이동: Dyuman Joshi 2024년 2월 22일
Dyuman, You mind adding that as an answer instead of a comment so I can accept and close the thread. Thanks for your help!
Dyuman Joshi
Dyuman Joshi 2024년 2월 22일

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Ayush Modi
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
expr = 
% Convert the expression to a string
exprStr = char(expr);
% Replace '1/cos' with 'sec' in the string
exprStr = strrep(exprStr, '1/cos', 'sec')
exprStr = 'sec(x)^2'
Note - This will not prevent the simplification of expression by MATLAB.
  댓글 수: 1
Paul Dostert
Paul Dostert 2024년 2월 20일
Thanks Ayush. I was hoping there was something along the lines of "trig = "six"" or something like that which would keep/simplify in terms of most efficient representations with all six trig functions. I ended up just hard-coding all of the integrals/derivatives using tan and sec. Thanks for your response thourgh.

댓글을 달려면 로그인하십시오.


John D'Errico
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
X = 
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)
ans = 
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)
ans = 
Another option is to use rewrite:
rewrite(X,'sec')
Error using rewrite
Expected input to match one of these values:

'sincos', 'sin', 'cos', 'tan', 'cot', 'sinhcosh', 'sinh', 'cosh', 'tanh', 'coth', 'asin', 'acos', 'atan', 'acot', 'asinh', 'acosh', 'atanh', 'acoth', 'exp', 'log', 'sqrt', 'heaviside', 'piecewise', 'expandroot', 'expandsum', 'CGS', 'EMU', 'ESU', 'GU', 'SI', 'US'

The input, 'sec', did not match any of the valid values.
And rewrite sometimes works, but 'sec' was not an option.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by