does 'VPA' changes the type of a data variable ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone
I have a question about the data type.
I know that all data are double floating-point in Matlab by default.
I've written this code and when I use 'whos function' for 'z', Matlab says that z is 'double' which is what I expect.
s=500;
t=[12 25 36 12 1 8 9 20 9 7 5 2 74];
z=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:10
z=z+t(i);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z=s-z;
whos function:
whos z
Name Size Bytes Class Attributes
z 1x1 8 double
I've added one line (line 8) and used VPA, when I repeat what I've said above, Matlab says that z is 'syms'.
s=500;
t=[12 25 36 12 1 8 9 20 9 7 5 2 74];
z=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:10
z=z+t(i);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z=vpa(z,10);
z=s-z;
whos function:
whos z
Name Size Bytes Class Attributes
z 1x1 112 sym
does VPA change the data type?
I really appreciate any explanation for this change and totally about syms.
0 Commenti
Risposte (1)
Chunru
il 27 Ago 2022
vpa(x) uses variable-precision floating-point arithmetic (VPA) to evaluate each element of the symbolic input x.
The input to x is supposed to be symbolic.
syms x
p = sym(pi);
piVpa = vpa(p)
class(p) % The type is sym
a = sym(1/3);
f = a*sin(2*p*x);
fVpa = vpa(f)
0 Commenti
Vedere anche
Categorie
Scopri di più su Numbers and Precision in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!