Hello,
grad =
I have an output like this, but I want at most 6 digit of numbers. How can I change it? Please help me.
Thank you so much

답변 (1개)

Paul
Paul 2023년 6월 6일

1 개 추천

Try:
vpa(grad,6)

댓글 수: 9

John Adams
John Adams 2023년 6월 6일
still same
Paul
Paul 2023년 6월 6일
Can you post the the code that generates grad, or save it to a .mat file and post add it to your question using the paper clip icon. Hard to help without being able to recreate the results.
John Adams
John Adams 2023년 6월 6일
편집: Walter Roberson 2023년 6월 6일
syms x y
x1=2.234;
y1=2.24;
x2=5.34;
y2=5.5452;
x3=2.123;
y3=5.153;
x4=3.656;
y4=5.03;
x5=2.6001;
y5=6.253;
x6=1.933;
y6=3.411;
A= [1 x y x^2 x*y y^2]
A = 
B= [1 x1 y1 x1^2 x1*y1 y1^2;1 x2 y2 x2^2 x2*y2 y2^2;1 x3 y3 x3^2 x3*y3 y3^2;
1 x4 y4 x4^2 x4*y4 y4^2;1 x5 y5 x5^2 x5*y5 y5^2;1 x6 y6 x6^2 x6*y6 y6^2;]
B = 6×6
1.0000 2.2340 2.2400 4.9908 5.0042 5.0176 1.0000 5.3400 5.5452 28.5156 29.6114 30.7492 1.0000 2.1230 5.1530 4.5071 10.9398 26.5534 1.0000 3.6560 5.0300 13.3663 18.3897 25.3009 1.0000 2.6001 6.2530 6.7605 16.2584 39.1000 1.0000 1.9330 3.4110 3.7365 6.5935 11.6349
invB= inv(B)
invB = 6×6
-2.0905 1.3396 -12.3014 -4.8507 7.2358 11.6671 2.2593 -0.8656 3.8676 2.2793 -2.0882 -5.4524 -0.2062 -0.1204 3.8107 0.7954 -2.4315 -1.8479 0.1644 0.1879 0.6403 -0.3728 -0.2535 -0.3663 -0.6349 -0.0427 -1.6263 0.0996 0.7106 1.4938 0.1718 0.0278 0.0135 -0.1317 0.1166 -0.1981
C= A * invB
C = 
It is the simplified code. C goes like this.
syms x y
x1=2.234;
y1=2.24;
x2=5.34;
y2=5.5452;
x3=2.123;
y3=5.153;
x4=3.656;
y4=5.03;
x5=2.6001;
y5=6.253;
x6=1.933;
y6=3.411;
A= [1 x y x^2 x*y y^2]
A = 
B= [1 x1 y1 x1^2 x1*y1 y1^2;1 x2 y2 x2^2 x2*y2 y2^2;1 x3 y3 x3^2 x3*y3 y3^2;
1 x4 y4 x4^2 x4*y4 y4^2;1 x5 y5 x5^2 x5*y5 y5^2;1 x6 y6 x6^2 x6*y6 y6^2;]
B = 6×6
1.0000 2.2340 2.2400 4.9908 5.0042 5.0176 1.0000 5.3400 5.5452 28.5156 29.6114 30.7492 1.0000 2.1230 5.1530 4.5071 10.9398 26.5534 1.0000 3.6560 5.0300 13.3663 18.3897 25.3009 1.0000 2.6001 6.2530 6.7605 16.2584 39.1000 1.0000 1.9330 3.4110 3.7365 6.5935 11.6349
invB= inv(B)
invB = 6×6
-2.0905 1.3396 -12.3014 -4.8507 7.2358 11.6671 2.2593 -0.8656 3.8676 2.2793 -2.0882 -5.4524 -0.2062 -0.1204 3.8107 0.7954 -2.4315 -1.8479 0.1644 0.1879 0.6403 -0.3728 -0.2535 -0.3663 -0.6349 -0.0427 -1.6263 0.0996 0.7106 1.4938 0.1718 0.0278 0.0135 -0.1317 0.1166 -0.1981
C= A * invB
C = 
vpa(C,6)
ans = 
But what I suspect you are looking for is
digits(6)
FPO = sympref('floatingpointoutput', true);
syms x y
x1=2.234;
y1=2.24;
x2=5.34;
y2=5.5452;
x3=2.123;
y3=5.153;
x4=3.656;
y4=5.03;
x5=2.6001;
y5=6.253;
x6=1.933;
y6=3.411;
A= [1 x y x^2 x*y y^2]
A = 
B= [1 x1 y1 x1^2 x1*y1 y1^2;1 x2 y2 x2^2 x2*y2 y2^2;1 x3 y3 x3^2 x3*y3 y3^2;
1 x4 y4 x4^2 x4*y4 y4^2;1 x5 y5 x5^2 x5*y5 y5^2;1 x6 y6 x6^2 x6*y6 y6^2;]
B = 6×6
1.0000 2.2340 2.2400 4.9908 5.0042 5.0176 1.0000 5.3400 5.5452 28.5156 29.6114 30.7492 1.0000 2.1230 5.1530 4.5071 10.9398 26.5534 1.0000 3.6560 5.0300 13.3663 18.3897 25.3009 1.0000 2.6001 6.2530 6.7605 16.2584 39.1000 1.0000 1.9330 3.4110 3.7365 6.5935 11.6349
invB= inv(B)
invB = 6×6
-2.0905 1.3396 -12.3014 -4.8507 7.2358 11.6671 2.2593 -0.8656 3.8676 2.2793 -2.0882 -5.4524 -0.2062 -0.1204 3.8107 0.7954 -2.4315 -1.8479 0.1644 0.1879 0.6403 -0.3728 -0.2535 -0.3663 -0.6349 -0.0427 -1.6263 0.0996 0.7106 1.4938 0.1718 0.0278 0.0135 -0.1317 0.1166 -0.1981
C= A * invB
C = 
sympref('floatingpointoutput', FPO) %restore setting
ans = logical
1
John Adams
John Adams 2023년 6월 6일
Thanks a lot. :)
John Adams
John Adams 2023년 6월 6일
편집: John Adams 2023년 6월 6일
I realized that when I change the number inside of digits(6) or vpa(C,6) answer always starts with 0.1644 why is it like that? Even, Digits = 32 is shown in command window answer has 4 digits
Walter Roberson
Walter Roberson 2023년 6월 6일
The sympref always uses 4. I misled when I showed digits(6) as if it controlled the output digits for the sympref
Paul
Paul 2023년 6월 6일
To be clear, 'floatingpointoutput' = true only affects the display of results, not the results themselves.

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

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

질문:

2023년 6월 6일

댓글:

2023년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by