Round coefficients of symbols
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a solution matrix with equations and coefficients in front of symbols. I want to round them to a certain decimal.
example: X=[1.89545464564*S+0.00000085*M, 1.00000055*S-0.68129354234*M; 0.00000000345*S+0.00000346*M, 1.00004353*S+1.68129354234*M];
How to round the coefficients that are in front of S and M in my matrix to something like 2 or 3 decimal places.
Thank you!
0 commentaires
Réponses (4)
Andrei Bobrov
le 19 Juin 2013
syms M S
X=[1.89545464564*S+0.00000085*M, 1.00000055*S-0.68129354234*M; 0.00000000345*S+0.00000346*M, 1.00004353*S+1.68129354234*M];
out = vpa(X,4);
0 commentaires
Image Analyst
le 7 Nov 2014
Use the second argument for round(). From the (R2014b) help for round():
Y = round(X,N) rounds to N digits:
N > 0: round to N digits to the right of the decimal point.
N = 0: round to the nearest integer.
N < 0: round to N digits to the left of the decimal point.
1 commentaire
Carlos
le 8 Déc 2022
Hope it's not too late:
syms M S
X=vpa([1.89545464564*S+0.00000085*M, 1.00000055*S-0.68129354234*M; 0.00000000345*S+0.00000346*M, 1.00004353*S+1.68129354234*M]);
for i = 1:length(X)
Coef = coeffs(X(i));
for j = 1:length(Coef)
if Coef(j) < 0.001 %you can change 0.001 to adjust precision
X(i) = subs(X(i),Coef(j),0);
end
end
end
X = vpa(X,5) %use vpa becouse the function subs adds unwanted decimals.
0 commentaires
Voir également
Catégories
En savoir plus sur Conversion Between Symbolic and Numeric dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!