The usual way to evaluate (i-e get a numerical value) for specific values of input variables (more than one variable) is to either use "subs" function or create a symbolic function "symfun". It takes a long time if I try to repeat this process 50000 times in a "for" loop for different variable values.
For example, the following code took 10 minutes on a computer with pretty good processor and ram specifications.
>> syms x y zf = 2*y*z*sin(x) + 3*x*sin(z)*cos(y) - z^3;g(x,y,z) = gradient(f, [x, y, z])ticfor i=1:50000 % d = double(subs(g,[x,y,z],[1,2,3]));
d = double(g(1,2,3));endtoc>> g(x, y, z) = 3*cos(y)*sin(z) + 2*y*z*cos(x) 2*z*sin(x) - 3*x*sin(y)*sin(z) 2*y*sin(x) - 3*z^2 + 3*x*cos(y)*cos(z)>> Elapsed time is 600.937920 seconds. Is there a simple and faster way to achieve this workflow ?
Best Answer