# Function diagm() does not work in Julia v1.0.5?

**URL:** https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359
**Category:** Tooling
**Created:** [November 16, 2022, 3:54pm UTC](https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359 "2022-11-16T15:54:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jorgedltn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jorgedltn/32/32981_2.png) [@Jorgedltn](https://discourse.julialang.org/u/Jorgedltn)
#### Post date: [November 16, 2022, 3:54pm UTC](https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359/1 "2022-11-16T15:54:26Z")

</div>

I am trying to construct a diagonal matrix by using the function diagm() within a test project that is formed by a group of Julia files. When I include all of these files into the Julia terminal to run and prove if these files do not present any error, the next error is show up: “ERROR: LoadError: UndefVarError: diagm not defined”.

I was doing some small external tests trying to reproduce this running only the function command in other Julia terminal. I check these command in the versions 1.0.5 and in version 0.3.12.  
The result was the following:  
Using the v0.3.12, the error does not appear and the function works perfectly, but when I tried to do the same in the v1.0.5 the error showed up.

The code lines I am using for this unique test are those that I will show in the screenshot below:

 ![Captura de pantalla (200)](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b49f40d78810ebec9128ec71c3d3e4127a6f7a3.png)

---

<div class="post-metadata">

### Author: ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)
#### Post date: [November 16, 2022, 4:09pm UTC](https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359/2 "2022-11-16T16:09:40Z")

</div>

There used to be many changes before the version 1.x.y. Code that worked in versions 0.3.x is probably not going to work because of those changes.

In versions above 1 you need to first use LinearAlgebra, which is the standard library that contains that function.

```julia
julia> using LinearAlgebra

julia> v = [3,4]
2-element Vector{Int64}:
 3
 4

julia> diagm(0=>v)
2×2 Matrix{Int64}:
 3 0
 0 4

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [November 16, 2022, 4:20pm UTC](https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359/3 "2022-11-16T16:20:07Z")

</div>

This will work in 1.x if you add `using LinearAlgebra`

---

<div class="post-metadata">

### Author: ![Jorgedltn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jorgedltn/32/32981_2.png) [@Jorgedltn](https://discourse.julialang.org/u/Jorgedltn)
#### Post date: [November 21, 2022, 4:21pm UTC](https://discourse.julialang.org/t/function-diagm-does-not-work-in-julia-v1-0-5/90359/4 "2022-11-21T16:21:22Z")

</div>

Thanks to you guys, I was forgetting to add the library ‘LinearAlgebra’. That was really helpfull to me!
