# Absolute value error?

**URL:** https://discourse.julialang.org/t/absolute-value-error/87579
**Category:** New to Julia
**Created:** [September 21, 2022, 3:14pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579 "2022-09-21T15:14:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ejlongman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ejlongman/32/36801_2.png) [@ejlongman](https://discourse.julialang.org/u/ejlongman)
#### Post date: [September 21, 2022, 3:14pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579/1 "2022-09-21T15:14:13Z")

</div>

Hello! I am using value function iteration to maximize a Bellman equation. When I check the difference between two vectors then take the absolute value, I get an error from the “di” line:

```julia
    subt = vnew - v
    println(subt)
    di = abs.(subt)
    v = vnew

```

For context, “subt” looks like:  
[41474.08152719693 46131.513156937144; 42846.34653896693 47535.076846955286; 45098.84448852737

MethodError: no method matching isless(::Float64, ::Matrix{Float64})  
Closest candidates are:  
isless(::T, ::T) where T\<:Union{Float16, Float32, Float64} at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/float.jl:460  
isless(::AbstractFloat, ::AbstractFloat) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/operators.jl:184  
isless(::Real, ::AbstractFloat) at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/operators.jl:185

But

---

<div class="post-metadata">

### Author: ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)
#### Post date: [September 21, 2022, 3:35pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579/2 "2022-09-21T15:35:53Z")

</div>

It’s probably not hard to track this down. Maybe someone else can see the issue already; I don’t. Some things that might help

- the expression for `subt` that you gave is incomplete. What is the full expression?
- You wrote “But”… Is something missing?

---

<div class="post-metadata">

### Author: ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)
#### Post date: [September 21, 2022, 3:36pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579/3 "2022-09-21T15:36:10Z")

</div>

Perhaps some context is missing from your post. I have no problems (v 1.8.1, Intel Mac)

```julia
julia> v=rand(3); vnew=rand(3); subt=vnew-v;

julia> println(subt)
[2.32118e-01, -6.61210e-02, 2.67815e-01]

julia> di=abs.(subt);

julia> v = vnew;

julia> di
3-element Vector{Float64}:
 2.32118e-01
 6.61210e-02
 2.67815e-01

```

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [September 21, 2022, 4:41pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579/4 "2022-09-21T16:41:27Z")

</div>

You don’t happen to have a variable called `abs` or otherwise accidentally redefined the `abs` function?

What’s the full stacktrace?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 21, 2022, 5:36pm UTC](https://discourse.julialang.org/t/absolute-value-error/87579/5 "2022-09-21T17:36:58Z")

</div>

> [@ejlongman](#):
>
> When I check the difference between two vectors then take the absolute value,

`abs.(subt)` is the _elementwise_ absolute value, which returns a vector. It sounds like you want the _norm_ of the difference, i.e. a single number `norm(vnew - v)`. (The [`norm` function](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.norm) is provided by the `LinearAlgebra` standard library.)

(Your `MethodError: no method matching isless` sounds like it is coming from a later line in your code, where you are comparing `di` to a scalar, e.g. you have `di ≤ sometolerance`, which fails because you can’t compare a vector to a scalar.)
