# Viscircles and Norm not defined

**URL:** <https://discourse.julialang.org/t/viscircles-and-norm-not-defined/87380>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [September 16, 2022, 4:38pm UTC](https://discourse.julialang.org/t/viscircles-and-norm-not-defined/87380 "2022-09-16T16:38:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric.O](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@Eric.O](https://discourse.julialang.org/u/Eric.O)\
**Post date:** [September 16, 2022, 4:38pm UTC](https://discourse.julialang.org/t/viscircles-and-norm-not-defined/87380/1 "2022-09-16T16:38:01Z")

</div>

I Keep getting this 3 errors with my code. I made some search to correct them but the options are not working. I will be glad if anyone can give me some guidance, please. this are my errors

1. The “hold on” for plots is not working in Julia so I used plot!() but am not getting any results. What can I use to replace hold on for plots in Julia.
2. viscircles is not defined is another error. What do I use to replace viscicles.
3. I have Norm[j]=norm(Xk-[x[j],y[j]]) which I see it to be defined but I keep getting Norm is not defined.

How do I correct this please. Any help will be greatly appreciated please. Thank you.

```julia
using PyPlot
using Plots
pyplot()
using LinearAlgebra, BenchmarkTools

n=7
W=[4 3 5 6 7 6 5]
x=[33 15 2 5 39 17 11]
y=[41 11 4 45 3 26 4]
plot(x,y, "ko")
 hold on

x-y
c=W.*(x-y)
d = norm(c) # this is two norm()
x0=sum(W.*x)/sum(W)
y0=sum(W.*y)/sum(W)
Xk=[x0,y0]

for r=10:30:30
    viscircles[[x0,y0],r]
    plot(x0,y0, "kv")
    hold on
end

for j=1:n
    Norm[j]=norm(Xk-[x[j],y[j]]);# calculate the distance from the initial point to all other points, 2-norm()
    Top[j]=W[j]*x[j]/Norm[j]; # top of 2.5
    Bottom[j]=W[j]/Norm[j];# bottom of 2.5
    S[j]=W[j]/Norm[j]; # 2.8
    Gradx[j]=W[j]*(x0-x[j])/Norm[j]; # gradiaent in x-direction
    Grady[j]=W[j]*(y0-y[j])/Norm[j]; # gradiaent in y-direction
end

Tx=sum(Top)/sum(Bottom)
Gradx=sum(Gradx)
Grady=sum(Grady)
SatBarx=(sum(S))^(-1)

NewX=Xk-[SatBarx*Gradx, SatBarx*Grady]
count=0

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 16, 2022, 5:57pm UTC](https://discourse.julialang.org/t/viscircles-and-norm-not-defined/87380/2 "2022-09-16T17:57:22Z")

</div>

1. Plots are displayed when the code you are evaluating returns a plot object. You are plotting in a loop and looks return `nothing` in Julia. You need to call `current()` after your loop to display the plot.
2. You need to tell people what `viscircles` is. There is no reason to expect that any random Matlab function exists in Julia, or that people know what Matlab functions do.
3. You are not defining `Norm` in your code, so it is undefined. Julia is case sensitive so `Norm` is not the same as `norm`. As a general piece of advice it is not a good idea to define objects which share the name of built in functions like `norm`, as you can easily overwrite them and break your program, also it makes your code harder to reason about when names don’t mean what they normally mean.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 16, 2022, 6:57pm UTC](https://discourse.julialang.org/t/viscircles-and-norm-not-defined/87380/3 "2022-09-16T18:57:51Z")

</div>

One difference to MATLAB is that you need to define arrays before you can write into them.  
For example, if you add this line before the for loop, the second error will probably disappear:

```julia
Norm = zeros(n)

```

(This is because Julia doesn’t assume that a line like `Norm[1] = 1.0` should create a new vector if it doesn’t exist already. This is because the syntax could also represent many other things in Julia (such as a `Dict` etc…)
