Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What reason is different result, when I change R code to julia code? Thank you #12362

Closed
meibujun opened this issue Jul 29, 2015 · 3 comments
Closed

Comments

@meibujun
Copy link

R code
f=c(0.5,0.5)
n.al <- length(f)
P.1 <- P.2 <- array(0,dim=rep(n.al,4))
    for(a2 in 1:n.al) for(a1 in 1:n.al)
    for(a3 in 1:n.al) for(a4 in 1:n.al)
    {
        if (a1==a3 & a2==a4)
        {
            P.2[a1,a2,a3,a4] <- f[a1]*f[a2]
            P.1[a1,a2,a3,a4] <- f[a1]*f[a2]*(f[a1]+f[a2])/2
        }
        if (a1==a3 & a2!=a4)
        {
            P.1[a1,a2,a3,a4] <- f[a1]*f[a2]*f[a4]/2
        }
        if (a1!=a3 & a2==a4)
        {
            P.1[a1,a2,a3,a4] <- f[a1]*f[a3]*f[a2]/2
        }
    }
julia code
f=Array(Float64,1,2)
f[:,:]=0.5
p1=Array(Float64,nal,nal,nal,nal)
p2=Array(Float64,nal,nal,nal,nal)
p1[:,:,:,:]=0.0
p2[:,:,:,:]=0.0
    for (a2 = 1:nal)  for (a1 = 1:nal)
    for (a3 = 1:nal)  for (a4 = 1:nal)
       if (a1==a3 & a2==a4)
          p2[a1,a2,a3,a4] = f[a1]*f[a2]
          p1[a1,a2,a3,a4] = f[a1]*f[a2]*(f[a1]+f[a2])/2.0
       end

       if (a1==a3 & a2!=a4)
          p1[a1,a2,a3,a4] = f[a1]*f[a2]*f[a4]/2.0
       end

       if (a1!=a3 & a2==a4)
          p1[a1,a2,a3,a4] = f[a1]*f[a3]*f[a2]/2.0
       end
    end end
    end end 
@meibujun meibujun changed the title why do I change R code to julia code, but I have different result. What reason different result, when I change R code to julia code? Thank you Jul 29, 2015
@meibujun meibujun changed the title What reason different result, when I change R code to julia code? Thank you What reason is different result, when I change R code to julia code? Thank you Jul 29, 2015
@meibujun
Copy link
Author

untitled

@ihnorton
Copy link
Member

This is not the right place for a question like this. Please use julia-users mailing list or Stackoverflow.

@tkelman
Copy link
Contributor

tkelman commented Jul 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants