Problem: Given the vector say \[ v={1,2,4} \]
Find its norm for \(p=1,2,\infty \)
Mathematica Remove["Global`*"]; v = {{1}, {2}, {4}}; p = {1, 2, Infinity}; Map[Norm[v,#]&,p]
|
{7,Sqrt[21],4} |
Matlab clear all; close all; v=[1 2 4]; p=[1,2,inf]; arrayfun(@(i) norm(v,p(i)),1:length(p))
|
ans = 7.0000 4.5826 4.0000 |