MATLAB: How to evaluate the value of expression of many variables at a given point or vector

symbolic expression evaluation

Let us consider a function of two variable as, f = @(t1,t2)t1.*1.440745596517226e-5-t2.*(t1.*4.427411218097436e-10-1.49134455586144e-5).*1.0+2.5
If we wish to evaluate the value of the function f at vector T = [t1, t2]=[1,1]. The command feval(f, T) gives the following error.
Error using @(t1,t2)t1.*1.440745596517226e-5-t2.*(t1.*4.427411218097436e-10-1.49134455586144e-5).*1.0+2.5 Not enough input arguments.
However f(1,1) or feval (f,1,1) evaluates the value of function at given points. But if the number of variables are very large like say 100 then how to evaluate this function? Manual entry of 100 variables (like: f(1,1) or feval (f,1,1) ) is time consuming and condition gets worse in the iterations where the number of variables may change. Please consider this issue. Thanks in advance from my side.

Best Answer

You may define your function symbolically and then by using subs command, you can find the value at a certain point for the function. For instance:
syms t1 t2
fun=t1.*1.440745596517226e-5-t2.*(t1.*4.427411218097436e-10-1.49134455586144e-5).*1.0+2.5;
then
funVal=subs(fun,{t1,t2},{1,1});
Also, a definition might be as follows for many variables:
t=sym('t',[50 1]);
t is a symbolic vector which holds 50 different variables within. Then the same procedure applies for subs command
subs(fun,t,ones(50,1));