Decreasing digits of answer

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

Answers (1)

Try:
vpa(grad,6)

9 Comments

still same
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.
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
Thanks a lot. :)
John Adams
John Adams on 6 Jun 2023
Edited: John Adams on 6 Jun 2023
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
The sympref always uses 4. I misled when I showed digits(6) as if it controlled the output digits for the sympref
To be clear, 'floatingpointoutput' = true only affects the display of results, not the results themselves.

Sign in to comment.

Products

Release

R2022b

Asked:

on 6 Jun 2023

Commented:

on 6 Jun 2023

Community Treasure Hunt

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

Start Hunting!