## For Loops With Matrices

### Kelly McGuire (view profile)

on 11 Apr 2017
Latest activity Commented on by Star Strider

on 11 Apr 2017

### Star Strider (view profile)

So, I am trying to perform a global fit on 15 data traces obtained from electrophysiology. The first three traces had a concentration of 10 micromolar, the second three traces had a concentration of 100 micromolar, the third three traces had 500 micromolar, the fourth had 1 millimolar, and the fifth had 10 millimolar. The traces are nanoamps vs milliseconds. Ok, so I want to globally fit these 15 traces using a nonlinear custom nonlinear function with lsqcurvefit. Fitting the first three traces was simple since they all had the same concentration. How would I fit all of these traces using my nonlinear function and lsqcurvefit in a loop where the concentration changes? I thought maybe putting all of the xdata (milliseconds) in one matrix, and the ydata (nanoamps) in another matrix and using those as the xdata and ydata that are called into lsqcurvefit, and that worked if the concentration is a fixed number. Now, how would I do this if my matrix was 15 dimensions, and every three columns I needed the nonlinear function to start using a different concentration? I hope this was mostly clear.

### Star Strider (view profile)

on 11 Apr 2017

Mostly, but not entirely.
The lsqcurvefit function is the correct choice.
It would be necessary to know the equations you want to fit, and if the concentration of the unknown substance could be parameterised within them.
How are the data related to the concentrations?

Show 1 older comment
Star Strider

### Star Strider (view profile)

on 11 Apr 2017
I’m not quite certain I understand ‘k1’ and ‘k-2’. I don’t need to know the details, just a bit more about your study. (I assume you know everything except ‘k1’ and ‘k-2’.)
Are they assumed to be constant at the time you’re recording your data, with the drug at an equilibrium concentration? (This is relatively straightforward if I understand your problem correctly.)
Or do they dynamically change during the study as the drug diffuses, and you’re also modeling them as functions of time? (This is much more difficult, and may not be possible to model.)
Is the drug concentration represented anywhere in your model?
Your rather mind-boggling model isn’t the issue. (I’m assuming you’ve coded it and that your objective function works.) I’m curious about what your data represent, and what you’re fitting.
Also, do you have a paired study design, so you have one set of data before the drug is administered to each preparation, and a second set at the equilibrium concentration of the drug?
Kelly McGuire

### Kelly McGuire (view profile)

on 11 Apr 2017

See attachment. I am measuring the current passing through the ion channel before and after drug is added to the bath. Before the red arrow (i.e. -180 nA), the ion channel has been activated by acidifying the bath. At the red arrow, drug is added to the bath and begins to block the current (i.e. blocking the ion channel). Notice though how it is an exponential block. k1 is the on rate constant of the drug and k-2 is the off rate constant of the drug. The ratio of these numbers tells us the EC50 (effective concentration that blocks 50% of the current). k1 and k-2 wouldn't change, they would be fixed numbers depending on the drug, we just don't know what those numbers are beforehand. Where the trace levels off is the equilibrium of the drug in the channel vs out of the channel, and that depends on k1 and k-2. In the equation I showed you, the drug concentration does show up in those sums as Co. The on rate, k1, is dependent on drug concentration, so everywhere there is a k1 in my equation, there is also a time-dependent drug concentration. The reason for time dependence in the drug concentration is because of diffusion up to the channel when the drug is added is time dependent (i.e. the concentration in the bath doesn't jump to, for example, 100 micromolar, it takes time for the unstirred layer around the channel to reach the maximum concentration).

Star Strider

### Star Strider (view profile)

on 11 Apr 2017
I assume the varying concentration of ‘Co’ are accounted for by ‘k1’.
I would define the start time as the time the drug is added to the bath.
It seems that if you have all the other constants (such as ‘Co’, whenever in your experiment you measure it), this is a relatively straightforward two-parameter estimation problem. If so, design your objective function to accept ‘Co’ as an input argument. You may need to use a loop in your objective function to provide the appropriate values of ‘Co’ to fit each column (or row) in your objective function matrix. This is going to be slow, but should be successful. Turn off the sleep option for your computer while you run this.