how drop near zero imaginary terms from symbolic result?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm doing some symbolic matrix manipulations with complex valued matrices. Some of my results are as below.
Zaa*(1 + 3i/36028797018963968) + Zab*(1 + 3i/36028797018963968)
Is there a way to tell Matlab to ignore those near zero imaginary results so the answer will be reported simply as,
Zaa + Zab
댓글 수: 4
Jamie Steel
2022년 8월 30일
편집: Jamie Steel
2022년 8월 30일
@John D'Errico Ah I see, perhaps I misinterpreted the expression - I assumed the symbols were only Zaa and Zab, and that the following complex number z was some numerical result multiplying them. That is horribly messy though! My experience with symbolic manipulation is certainly limited enough such that I've never run into trouble like that thankfully
답변 (1개)
Moksh
2023년 9월 21일
Hi Russell,
I understand that you are attempting to eliminate the imaginary part in the intermediate term if it is close to zero, as shown in the example provided.
You can utilize the "abs" and "imag" functions in MATLAB to obtain the magnitude of the imaginary part. By comparing this magnitude with a threshold value, which can be adjusted as needed, you can determine if the imaginary part is sufficiently close to zero.
Here is an example code:
syms Zaa Zab
% Get the imaginary part in z
z = 1 + 3i/36028797018963968;
imag_z = imag(z);
tol = 1e-5;
% Ignore the imaginary part in z if it is near zero
if abs(imag_z) < tol
z = real(z);
end
% Define the main result
Z = Zaa * z + Zab * z;
disp(Z)
For more understanding about the above used functions, please refer to the following documentation:
- imag: https://in.mathworks.com/help/matlab/ref/imag.html
- abs: https://in.mathworks.com/help/matlab/ref/abs.html
Hope this information helps!
Best Regards,
Moksh Aggarwal
댓글 수: 1
Dyuman Joshi
2023년 9월 21일
You are treating z as a numeric variable, which is not the case here as OP is dealing with symbolic variables.
This has been clarified above as well (1 year ago by @John D'Errico) - https://in.mathworks.com/matlabcentral/answers/1790480-how-drop-near-zero-imaginary-terms-from-symbolic-result#comment_2338445
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!