Search code examples
matlabeval

Evaluating a function defined symbolically with subs


eta0=-0.1806 - 0.1043i; 

syms lu
syms n

Gi(lu) = -(airy(2,lu)*int(airy(n),100,lu)-airy(lu)*int(airy(2,n),eta0,lu));

I am unable to evaluate a function defined like that e.g. Gi(2). How can this be done? I tried subs(Gi,lu,2) and eval(subs(Gi,lu,2)) but they don't work


Solution

  • Instead of messing around with symbolic toolbox, to evaluate the function itself, you can use anonymous function.

    eta0=-0.1806 - 0.1043i; 
    
    Gi = @(lu) -( airy(2,lu)*integral(@airy,100,lu)- ....
        airy(lu)*integral(@(x) airy(2,x),eta0,lu) );
    

    Symbolic function takes symbolic numbers, Anonymous function takes numeric numbers. Perhaps this is an easier way to perform a simple function.

    >> Gi(2)
    
    ans =
    
       0.1727 + 0.0019i