({{, (RefLink[NormFunction, paclet:ref/NormFunction]) 
is an option for functions such as (RefLink[FindFit, paclet:ref/FindFit]) and (RefLink[NDSolve, paclet:ref/NDSolve]) which gives a function to be minimized in generating results.}})

OpenersNotesSection(Spacer1)Details

(RefLink[NormFunction, paclet:ref/NormFunction])->f specifies that f[data] should be minimized in generating results.

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Find a "best" fit for data using different norms:

data=Table[Prime[x],{x,20}]

The default is to find the best least-squares fit:

FindFit[data,a x Log[b+cx],{a,b,c},x]

Use the ∞-norm instead:

FindFit[data,a x Log[b+cx],{a,b,c},x,NormFunction->(Norm[#,Infinity]&)]

Use the 1-norm:

FindFit[data,a x Log[b+cx],{a,b,c},x,NormFunction->(Norm[#,1]&)]

Use a 2-norm for estimating local error in solving an ODE:

sol2=First[x/.NDSolve[{x''[t]+x[t]==0,x[0]==1,x'[0]==0},x,{t,0,100π},NormFunction->(Norm[#,2]&)]]

Use an ∞-norm:

soli=First[x/.NDSolve[{x''[t]+x[t]==0,x[0]==1,x'[0]==0},x,{t,0,100π},NormFunction->(Norm[#,∞]&)]]

The error measure makes a difference in the solution quality:

{sol2[100π],soli[100π]}-1

OpenersExampleSection1(Spacer1)Scope  (1)

The norm is used for space and time in PDE solutions:

sol[p_]:=NDSolve[{D[u[t,x],t,t]==D[u[t,x],x,x],u[0,x]==Exp[-x^2],Derivative[1,0][u][0,x]==-Exp[-x^2],u[t,-L]==u[t,L]},u,{t,0,4L},{x,-L,L},NormFunction->(Norm[#,p]&)]

Plot the actual solution error, when using different error estimation norms:

L=10;Table[
Plot[Evaluate[(u[40,x]/.sol[p])-(Exp[-x^2]-2(Sqrt[π]))],{x,-L,L},PlotRange->All],{p,{1,2,3,∞}}]//Quiet

A plot of the best solution:

Plot3D[Evaluate[u[t,x]/.sol[1]],{t,0,40},{x,-10,10},Mesh->False,PlotPoints->20]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[FindFit, paclet:ref/FindFit])  ▪  (RefLink[NDSolve, paclet:ref/NDSolve])  ▪  (RefLink[DistanceFunction, paclet:ref/DistanceFunction])  ▪  (RefLink[Minimize, paclet:ref/Minimize])  ▪  (RefLink[NMinimize, paclet:ref/NMinimize])}})}})