MATLAB: Can someone tell me the difference between these codes

symbolicSymbolic Math Toolbox

syms h1(r,theta), rnu(theta,phi)
A = h1(r,theta) + rnu(theta,phi) %---> I know if I don't specify the argument, I'll get an argument not matching error.
A(r,theta,phi) = h1(r,theta) + rnu(theta,phi)
They both work and the result seem to be exactly the same. Am I missing something? Is there any difference between the above two lines?

Best Answer

There are differences between the two. First creates a symbolic expression, whereas second, create a symbolic function. To see the difference, check the output of the following for the second case
syms h1(r,theta) rnu(theta,phi)
A(r,theta,phi) = h1(r,theta) + rnu(theta,phi);
A(1,2,3)
Result
>> A(1,2,3)
ans =
h1(1, 2) + rnu(2, 3)
It treated A as a function and replaced r=1, theta=2, phi=3.
Now for the first A in your code
syms h1(r,theta) rnu(theta,phi)
A = h1(r,theta) + rnu(theta,phi); %---> I know if I don't specify the argument, I'll get an argument not matching error.
A(1,2,3)
You will get an error. Here A is a variable and MATLAB interpert (1,2,3) as index. To get the same output in this case, you will need to use subs()
>> subs(A, [r theta phi], [1 2 3])
ans =
h1(1, 2) + rnu(2, 3)