当值仅为“读取”,“从未分配”时,Julia代码更改变量值

时间:2016-05-02 20:09:28

标签: julia

首先,是否有人能够重新创建我得到的确切输出?第二,任何人都可以告诉我为什么u的值会在这个while循环中发生变化吗?据我所知,它应该是恒定的,但它会继续减少...或者,如果没有其他人可以重新创建这个问题,我将研究硬件错误。我猜测它是朱莉娅的新手用户错误,我尝试了全局和非全局的声明......谢谢!

Windows 7 Pro,HP Z820,64位,运行Julia 0.4.5

global u=[2.681726086033021];
eo1  = u;
tem5 = [9999.9];
ktr = [1];
tsize=[1];
axnl=[0.1641272464920273];
aynl=[-.08693550068203583];

sineo1 = sin(eo1); #initialize
coseo1 = cos(eo1);

while (maximum(abs(tem5)) >= 1.0e-12 )== 1 && maximum(ktr) <= 10
tem5orig = abs(tem5) .>= 1.0e-12; #we care about updating records *originally* meeting conditions
sineo1[tem5orig] = sin(eo1[tem5orig]);
coseo1[tem5orig] = cos(eo1[tem5orig]);
tem5temp1 = ones(tsize) - coseo1 .* axnl - sineo1 .* aynl;
tem5[tem5orig]  = tem5temp1[tem5orig];
tem5[tem5orig]   = (u[tem5orig] - aynl[tem5orig] .*coseo1[tem5orig] + axnl[tem5orig] .*sineo1[tem5orig] - eo1[tem5orig]) ./tem5[tem5orig];
tem5temp2 = tem5;
if (maximum(abs(tem5temp2)) > 0.95) == 1
    if maximum((abs(tem5temp2) .> 0.95) + (tem5temp2 .> 0) .> 1) == 1
        tem5temp2[((abs(tem5temp2) .> 0.95) + (tem5temp2 .> 0)) .> 1] = 0.95;
    end
    if (maximum((abs(tem5temp2) .> 0.95) + (tem5temp2 .<= 0)) .> 1) == 1
        tem5temp2[((abs(tem5temp2) .> 0.95) + (tem5temp2 .<= 0)) .> 1] = -0.95;
    end
end
tem5[tem5orig] = tem5temp2[tem5orig];
eo1[tem5orig] = eo1[tem5orig] + tem5[tem5orig];
ktrtemp = ktr + 1;
ktr[tem5orig] = ktrtemp[tem5orig];
println(ktr,",",tem5,",",eo1,",",sineo1,",",coseo1,",",u,",",tem5orig)
end


Output:
    [2],[-0.0042672957728621345],[2.6774587902601588],[0.4438285405397952],-0.8961117266291717],[2.6774587902601588],Bool[true]
    [3],[-0.003598989243971466],[2.6738598010161874],[0.4476484617059426],[-0.8942096257211187],[2.6738598010161874],Bool[true]
    [4],[-0.003035319765326468],[2.670824481250861],[0.4508638064529911],[-0.8925927559815393],[2.670824481250861],Bool[true]
    [5],[-0.0025599151808959153],[2.6682645660699653],[0.4535710297874299],[-0.8912201304602417],[2.6682645660699653],Bool[true]
    [6],[-0.0021589606544931365],[2.6661056054154724],[0.4558509890748779],[-0.8900561082086093],[2.6661056054154724],Bool[true]
    [7],[-0.0018208009676989512],[2.6642848044477736],[0.4577715213143546],[-0.8890698702990342],[2.6642848044477736],Bool[true]
    [8],[-0.0015356039646266324],[2.662749200483147],[0.45938958087161175],[-0.8882348861571498],[2.662749200483147],Bool[true]
    [9],[-0.001295076024952105],[2.661454124458195],[0.46075301570977506],[-0.8875283987086542],[2.661454124458195],Bool[true]
    [10],[-0.0010922216912360376],[2.660361902766959],[0.4619020457466296],[-0.8869309444004525],[2.660361902766959],Bool[true]
    [11],[-0.0009211406996768078],[2.659440762067282],[0.4628704952575407],[-0.8864259160358744],[2.659440762067282],Bool[true]

1 个答案:

答案 0 :(得分:5)

allWalletsaddress引用相同的数组对象。当您修改其中一个的内容时,另一个也会更改 - 因为它们是同一个对象。如果您初始化 var allWallets = []; docs.forEach(function(address) { console.log(address); allWallets.push(address.playerWallet); ,则修改eo1u不会更改。