I have the solution of an ode as an array $x(t_k)$ where $k=1,...K$.
I have another array which is an approximation to the solution of the ode, this array has also a length $k=1,...,K$.
How can I find the max distance between these two arrays? In other words I want to find the accuracy of my solution-approximation.
It is correct to do (in matlab):
Assume the solution-vector is called xSol and the approximation-vector is called xApprox
max((xSol - xApprox).^2)
or should I just do:
max(xSol - xApprox)
I would appreciate some justification of the answer, so I can learn!
thanks
If you do the first, then you must take the square root of the result.
The second will yield incorrect results, for example, if $x_{sol} = [0,0,0]$ and $x_{approx} = [0,10,10]$, then the maximum of their difference is $0$. What you must do is take the maximum of the absolute values of their distances. This is a function in matlab, i.e. for a vector $x=[x_0,x_1,\dots,x_n]$, the matlab function
norm(x,1)returns $$\max\{|x_1|,|x_2|,\dots,|x_n|\}$$For real numbers, this number is equal to $$\sqrt{\max\{x_1^2,x_2^2,\dots, x_n^2\}},$$ which is exactly the square root of the number your first formula would return.