MATLAB: How to define norm of a vector as a symbolic function

MATLABsymbolicsymbolic functionSymbolic Math Toolbox

I have defined the symbolic function as follows:
syms g(x,w)
g(x,w) = norm(w);
Then I have tested it using a symbolic variable:
v = sym('v', [1,2]);
g(x,v)
It only gives me the magnitude of of each entry of the vector, rather than the magnitude of the whole vector which is what I want:
ans =
[ (abs(v1)^2)^(1/2), (abs(v2)^2)^(1/2)]
How can I change it so it yields the norm of the whole vector? I would greatly appreciate your help!

Best Answer

Hi,
try:
syms g(x,v)
v = sym('v', [1,3]);
g(x,v) = norm(v)
g(x, v1, v2, v3) =
(abs(v1)^2 + abs(v2)^2 + abs(v3)^2)^(1/2)
>> pretty(g)
2 2 2
sqrt(|v1| + |v2| + |v3| )
Best regards
Stephan