How to stop internal simplification on symbolic expression? (Examples in Description)
조회 수: 35 (최근 30일)
이전 댓글 표시
Hey awesone friends, say in Live Editor, how to have an expression like below to be printed as exactly typed? Right now, by default, it auto "simplifies" to 1/((a+1)^n), which is not what I wanted. Wondering anyway to stop it.
syms a n
expr = (a+1)^(-n)
댓글 수: 0
답변 (1개)
Vaibhav
2023년 9월 25일
편집: Vaibhav
2023년 9월 25일
Hi Alex,
I understand that you want to print the expression exactly as it's typed in the Live Editor without it being automatically simplified. To achieve this, you can use the following workaround:
1. Define the expression as a string from the beginning, enclosing it in single quotes.
2. Use the `disp` function to display the expression in the Live Editor exactly as it is typed.
3. If you need to evaluate this expression later, you can convert it back to a symbolic expression using the `str2sym()` function.
Here's the code snippet for reference:
% Declare symbolic variables 'a' and 'n'
syms a n
% Define the expression as a string, enclosed in single quotes
expr = '(a+1)^(-n)';
% Display the expression exactly as it is typed
disp(expr);
% Convert the string back to a symbolic expression using str2sym for
% further calculations
ans = str2sym(expr);
This approach ensures that the expression appears exactly as you have typed it in the Live Editor, preserving its form.
Please refer to the following documentations for more information:
Hope this helps!
Thanks,
Vaibhav
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!