I found great help in the development of GUI from your blog article. Wish you all the best. ]]>

rng(42)

x = rand(1e6,1);

timeit(@() sin(x))

ans =

0.00458762052893101

timeit(@() vsin(x))

ans =

0.00240957876509779

x = x + 1e8;

timeit(@() sin(x))

ans =

0.051318654822932 % 11.2x slower

timeit(@() vsin(x))

ans =

0.00418348750972378 % 1.7x slower

sym_result = vpa(sin(sym(x(1))),20)

sym_result =

0.73411158904289725019

sin(x(1))

ans =

0.734111589042897

vsin(x(1))

ans =

0.734111589042897

x = rand(1e4,1) + 1e8;

sym_result = vpa(sin(sym(x)),20);

norm(sin(x) – double(sym_result))

ans =

2.20600085754237e-15

norm(vsin(x) – double(sym_result))

ans =

5.55111512312578e-17

result:

sin function takes 11.2x longer for very big numbers, while vsin takes 1.7x.

vsin result seems to be more accurate than sin.

I found one even more surprising example of rounding error that users should be aware of. Please check the following code:

format long

a = 77617;

b = 33096;

result = (333.75-a^2)*b^6+(11*a^2*b^2-121*b^4-2)*a^2+5.5*b^8+a/b/2

result =

1.172603940053179

a = sym(a);

b = sym(b);

f = (333.75-a^2)*b^6+(11*a^2*b^2-121*b^4-2)*a^2+5.5*b^8+a/b/2;

sym_result = vpa(f,20)

sym_result =

-0.82739605994682136814

The results are not of the same sign even. Clearly this problem occurs in all computational software due to a limited representation of numbers.

]]>