Search code examples
matlabmathsymbolic-math

Symbolic limit calculation, numeric value desired


I am trying to calculate a limit operation of a function inside. Here is what I did:

x = 0;
f = (cos(x)*cos(h/2)*sin(h/2))/(h/2) - (sin(x)*sin(h/2)*sin(h/2))/(h/2);
limit(f,h,0)
ans =
1

limit(f,h,1)
ans =
2*cos(1/2)*sin(1/2)

I want to see what the numeric value of 2*cos(1/2)*sin(1/2) is. How do I obtain this value?


Solution

  • You can use double to evaluate the final expression:

    double(limit(f,h,1))
    ans =
        0.8415
    

    limit is a symbolic function, so it outputs symbolic functions. You can use double (or single or whatever numeric type you want) to convert to a number.