matlab - Using variable-precision arithmetic together with functions -
i want compute function 4 decimal digit arithmetic in matlab. when run vpa(myfunc(), 4)
matlab returns same result when run myfunc()
while results different on paper. question how can use vpa()
without editing function?
edit in following example function sum()
, see results same (vpa()
affected last result)
>> x = exp([-10:0.01:1]); >> sum(x) ans = 273.1851 >> vpa(sum(vpa(x, 4)), 4) ans = 273.2
as @daniel said, decided write sum()
function vpa()
within it, result still same! wrong?
>> s = 0; x = -10:0.01:1, s = vpa( vpa(s,4) + vpa(exp(x),4) , 4); end >> s s = 273.2
to use vpa inside function, either have input vpa myfunc(vpa(4))
or use vpa inside function. code question same as:
x=myfunc() vpa(x,4)
first myfunc
called, result converted vpa.
i suggest run code in debugger , check data type of each number. if type vpa, vpa used.
Comments
Post a Comment