Help with convert error from Array{Float64, 2} to Float64

Hi
How do you clear this error please do help me at the earliest.

gmsh.initialize(ARGS)
gmsh.option.setNumber(“General.Terminal”, 1)
gmsh.model.add(“Jayanth model”)
using LinearAlgebra

gmsh.initialize(ARGS)
gmsh.option.setNumber(“General.Terminal”, 1)
gmsh.model.add(“Jayanth model”)

#Diemensions of the RVE_Box
x1 = 0.0; y1 = 0.0; z1 = 0.0;
l1 = 10.0; l2 = 10.0; l3 = 10.0;

gr = 1 # Graphite radius
fr = 1.1 # Ferrite radius
# x[v] = x[i];
toler = 2 * fr # tolerance value assumed
n = 5 # Number of nodules
g = zeros(n,1)
f = zeros(n,1)
b = gmsh.model.occ.addBox(x1, y1, z1, l1, l2, l3)

  gmsh.model.occ.synchronize()
  box = gmsh.model.addPhysicalGroup(3, [b], 1000)
  gmsh.model.setPhysicalName(3, box, "Box")
  gmsh.model.occ.synchronize()

  p = 1
  x = zeros(n,1);
  y = zeros(n,1);
  z = zeros(n,1);

for i = 1:n
global p,x,y,z,d,v
# global b
x[i] = norm(l1rand(1));
y[i] = norm(l2
rand(1));
z[i] = norm(l3*rand(1));

if i == 1
d = zeros(n,n)
x_new = zeros(n,1);
y_new = zeros(n,1);
z_new = zeros(n,1);

    v = zeros(n,n)
    #q = zeros(n,n)

end

      for j = 1:n

        d[i,j] = sqrt((x[i]-x[j])^2+(y[i]-y[j])^2+(z[i]-z[j])^2);
        if d[i,j] > toler
          #q[i,j] =  i
          v[i,j] = j
        else
          #q[i,j] = 0
          v[i,j] = 0

        end
      end


    #y[v]  = y[i];
  #  z[v]  = z[i];
  #  i[v]  = i;
    #j[v]  = j;

g[i] = gmsh.model.occ.addSphere(x, y, z, gr, (2i-1)+1+p, -π/2, π/2, 2π)
#println(“Graphite nodule number “,i,” is created.”)
gmsh.model.occ.synchronize()

f[i] = gmsh.model.occ.addSphere(x, y, z, fr, 2i+1+p, -π/2, π/2, 2π)
#println(“Ferrite number “,i,” is created.”)
gmsh.model.occ.synchronize()
end

LoadError: MethodError: Cannot convert an object of type Array{Float64,2} to an object of type Float64
Closest candidates are:
convert(::Type{T}, ::T) where T<:Number at number.jl:6
convert(::Type{T}, ::Number) where T<:Number at number.jl:7
convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250

Welcome @jayanth_jayasimha — I’ve moved your post into a new thread. While it has roughly the same error message, the cause is different than in the thread you posted.

Check out the PSA: make it easier to help you guide to make it a bit easier for folks to help you.

In this case, it looks like you’re wholesale converting a piece of MATLAB code into Julia. I highly recommend going piecemeal, a little at a time. This will help you narrow down where the issue is, which is 90% of understanding what the issue is.

In short, the error message is telling you that you’re trying to use an array like a single floating point number — something that MATLAB does (since everything is an array) but Julia is a bit pickier about.

3 Likes