Solve function supports only four decimal points

조회 수: 5 (최근 30일)
V. Freyr Gudmundsson
V. Freyr Gudmundsson 2022년 5월 31일
댓글: V. Freyr Gudmundsson 2022년 5월 31일
Is there a way to solve a system of equations like this with double precision without rounding? The theta vector here has precision double. But unless I limit the number of decimal points to 4 or fewer, I dont get an answer.
ts = 0.002;
syms a b;
eqn1 = 2+a*ts == 1.97720865074869;
eqn2 = -1-a*ts == -0.977208098949782;
eqn3 = ts^2*b == 0.00103667507747696;
%Note: solve function seems to accept only 4 decimal places.
%The round command is to accomodate this. Has nothing to do with the math.
sol = solve([eqn1, eqn2, eqn3],[a,b]); %solve for a and b, ts is known
aSol=double(sol.a)
bSol=double(sol.b)
If I just use double or increase the number of decimals to 5 I get : 0×1 empty double column vector.

답변 (2개)

Star Strider
Star Strider 2022년 5월 31일
I cannot run that because the ‘theta’ vector is missing.
However, the Symbolic Math Toolbox calculates in extended precision. If the results are limited to 4 decimal places, change the format setting to display more of them. Use the vpa function to change what the Symbolic Math Toolbox displays.
.
  댓글 수: 1
V. Freyr Gudmundsson
V. Freyr Gudmundsson 2022년 5월 31일
I failed at submitting a sample that would run. I have fixed that in the original post.
You will now see the problem when you run the code. It returns a struct with two 0x1 sym fields.
However, if you reduce the number of decimals down to four, it will come up with the right answer in two 1x1 sym fields.

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


Walter Roberson
Walter Roberson 2022년 5월 31일
Add the first two equations. The a*ts cancel out, leaving the equation 1 = theta1 + theta2. If that equation is not satisfied then there cannot be any solution to the system.

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by