2

I tried playing around with this example in the Julia documentation. My attempt was to make the cell split into two parts that have half of the amount of protein each, so I set Theta=0.5. However, the plot looks like this: enter image description here

It is obvious that the number of cells doubles every time they hit the target amount of protein, at the same time, since they are equal. How could I plot this? I also don't understand why the number of cells stops at 3 in the case below.

Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
Fabulini
  • 171
  • 1
  • 3
  • 11

1 Answers1

5

Plot the protein amount in each cell and think about the model you've created. After the first division, both cells have the same value. So at exactly the same time, you have an event fire. The "maximum" (whichever index is lower, so 1) will split, while 2 will keep growing above 1. But now that u[2] > 1, the rootfinding condition 1-maximum(u) will never hit zero again, and thus no more splits will occur. This means you'll have two splits total, i.e. 3 cells.

Remember, programs will do exactly what you tell them to. I assume that what you meant was, as your effect, split any cells that are greater than or equal to 1. If that's the affect! that you wanted, then you'd have to write it:

function affect!(integrator)
  u = integrator.u
  idxs = findall(x->x>=1-eps(eltype(u)),u)
  resize!(integrator,length(u)+length(idxs))
  u[idxs] ./ 2
  u[end-idxs:end] = 0.5
  nothing
end

would be one way to do it, and of course there are many others.

Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
  • Thank you, I understand what I did wrong in my code. However, I tried it with your version and it throws me the following error: "MethodError: no method matching -(::Int64, ::Array{Int64,1})". I used to get this error when I was doing simple operations with arrays and I was messing up the sizes... but what is the problem here? Also, isn't it enough to split any cells that are greater than 1? Because once it hits 1, it splits, it doesn't get the chance to grow more, right? – Fabulini Mar 23 '20 at 08:43