I have a small hiccup here. I am trying to write my Matlab code for a dynamical system in Mathematica. I have managed to get most of it except one part.
The Mathematica code for the system is
ctot = 2;
c1 = 0.185;
v1 = 80;
v2 = 0.11 ;
v3 = 27 ;
k3 = 0.146 ;
a2 = 0.2 ;
Gates = 500000;
OpenG = 50000;
alpha = 0.27;
k4 = 1.1 ;
v4 = 6 ;
Ir = 1 ;
d1 = 0.130 ;
d2 = 1.049 ;
d3 = 0.943 ;
d5 = 0.082 ;
sol = NDSolve[{c'[
t] == (v1 (pp[t]/(pp[t] + d1))^3 (c[t]/(c[t] + d5))^3 (OpenG/
Gates)^3) (ctot - (c1 + 1)*c[t]) -
v3*c[t]^2/(k3^2 + c[t]^2),
pp'[t] == v4 (c[t] + (1 - alpha) k4/(c[t] + k4)) - Ir*pp[t],
c[0] == 0.1, pp[0] == 2}, {c, pp}, {t, 0, 100}]
Plot[c[t] /. sol, {t, 0, 100}]
It seems all okay except for the part where I need to calculate OpenG
For the purpose of simplicity and to verify my Mathematica code I have assigned OpenG 50000. But this should be a varying parameter. In Matlab, this part of the code is to obtain the number of open gates(for example) driven by random conditions.
% randomly generate number of open gates
ini_states = unidrnd(2,100,3) - 1;
% a matrix of randomly generated zeros and ones. row corresponds
% to each gate, while column corresponds to the states in each gate's subunits.
alpha_h = 0.2*1.049*(2 + 0.13)/(2 + 0.943)*0.01; % a constant
openG = [length(nonzeros(all(ini_states,2))); zeros(100,1)];
% initial number of open gates. It checks for the rows that have all ones.
% if a row has colums with all ones then the gate is in the open state,
for i=1:100
y = rand(100,3); %probability that each gate's subunit will change its state
beta_h = 0.2*0.1*c[t]; %replace c[t] with rand just for the purpose to checking the code in MatLab
indces = (ini_states & y<beta_h) | (~ini_states & y<alpha_h);
% 'indces' matrix holds the position of the states that have been changed,
%indicated by a logical 1. indexing the values of 'indces' to ini_states
%and then inverting the values will give us the new state matrix.
ini_states(indces) = ~ini_states(indces);
%obtaining the new count on the number open gates
openG(i+1) = length(nonzeros(all(ini_states,2)));
end
Can anyone tell me how I can code this part?
RandomInteger
gets you a random integer.Select[#!=0&]
selects nonzero elements of a list.ConstantArray[0, {dims}]
creates a list whose elements are zero. $\endgroup$