필터 지우기
필터 지우기

how to reduce symbolic calculation precision?

조회 수: 8 (최근 30일)
EngM
EngM 2024년 1월 18일
댓글: Walter Roberson 2024년 1월 18일
The answer of the symbolic calculations may results in extermely small values, of the order of -33! Fo my use, I don't need such precision and would like any value lower than 1.e-6 (or anything else) to be round it to zero.
One solution suggested is to use vpa command. That didn't do anything to my calculations, matrices with entries of the order of 1.e-33 are still present decpite setting vpa('var',3) for example.
can you please help.
thanks.
  댓글 수: 4
Dyuman Joshi
Dyuman Joshi 2024년 1월 18일
편집: Dyuman Joshi 2024년 1월 18일
You can set the those values to 0 as well.
What is the value of x3? or what values can be used for x3, which can be used for an example?
EngM
EngM 2024년 1월 18일
well, it's cos(x3), so, the function is [-1,1] and the whole term should vanish when using lower precision calculation.

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

답변 (1개)

Walter Roberson
Walter Roberson 2024년 1월 18일
편집: Walter Roberson 2024년 1월 18일
The below code was developed to specifically search for a small constant multiplied by something
%create some demonstration data
syms nu
M = exp(randn(2,2) - 12) * nu + randn(2,2);
disp(char(vpa(M, 10)))
[0.000005657295524*nu + 1.201796311, 0.00001356942815*nu + 0.1714788358; 0.000003171547516*nu + 0.3197498794, 0.000003738587304*nu + 0.8981736893]
%now do the work
%constant times variable is always stored with the variable first (I thought it was the other way around!)
threshold = 1e-5;
op1 = @(expr) children(expr,1);
op2 = @(expr) children(expr,2);
ZapSmall = @(num, threshold) piecewise(num > -threshold & num < threshold, 0, num);
MM = simplify(mapSymType(M, 'times', @(expr) ZapSmall(op2(expr),threshold)*op1(expr)));
disp(char(vpa(MM, 10)))
[1.201796311, 0.00001356942815*nu + 0.1714788358; 0.3197498794, 0.8981736893]
There is a much more compact version for the case that vpa() has already been applied and all symbolic constants are to be examined.
mapSymType(M, 'vpareal', @(x) piecewise(abs(x)<=threshold, 0, x))
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 1월 18일
You have to be very careful when using this facility. If you have done a simplify() at any point then simplify() tends to rewrite A*x + B*y in terms of A*(x + B/A*y) where the leading coefficient can be quite large and the B/A coefficient can be quite small. This happens especially if you are working with bessel functions.

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

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by