You have several options ...
Option # 1: Automatically create a function
If you have version 4.9 (R2007b +) or later in Symbolic Tools, you can convert a symbolic expression into an anonymous function or an M file function using the matlabFunction function. Example from the documentation:
>> syms xy >> r = sqrt(x^2 + y^2); >> ht = matlabFunction(sin(r)/r) ht = @(x,y)sin(sqrt(x.^2+y.^2)).*1./sqrt(x.^2+y.^2)
Option # 2: Create a function manually
Since you have already written a set of symbolic equations, you can simply cut and paste part of this code into a function. Here is what your previous example would look like:
function output = f(beta,n1,n2,m,aa) u = sqrt(n2-beta.^2); w = sqrt(beta.^2-n1); a = tan(u)./w+tanh(w)./u; b = tanh(u)./w; output = (a+b).*cos(aa.*u+m.*pi)+(ab).*sin(aa.*u+m.*pi); end
When calling this function f you need to enter the values ββof beta and 4 constants, and it will return the result of the evaluation of your main expression.
Note: Since you mentioned wanting to find the zeros of f , you can try using SOLVE according to your symbolic equation:
zeroValues = solve(f,'beta');
gnovice
source share