MATLAB Answers

## Fit an equation with an integral

Asked by thatguy14

### thatguy14 (view profile)

on 2 Nov 2015
Latest activity Commented on by thatguy14

### thatguy14 (view profile)

on 2 Nov 2015
I have an equation that I am trying to find the best way to fit. In its original form it is:
A * convolution (func1,func2) from 0 to t or put correctly:
A* integral from 0 to t of (function 1(t')*exp(-A*(t-t')/B)dt')
Function 2 has two fit parameters I wish to recover. Function 1 is just a function of time and I have a curve for it.
I thought it might be easier to split the convolution as follows:
exp(-A(t-t')/B) = exp(-At/B)*exp(At'/B) and took out the first exponential since it is not a function of t'. I then tried to fit this, here is my code
kineticModel = @(ve,Ktrans,x) Ktrans.*exp(-Ktrans.*x./ve).*integral(@(x) Cpt(x).*exp(Ktrans.*x./ve),timePoints(1)./60,timePoints(end)./60);
[kineticFit, GOF] = fit((timePoints./60)',Ct',kineticModel);
This is giving me an error (subscript indicies must be real or positive integers or something similar. I found this is coming from the Cpt(x) term.
To be honest I am not sure this is correct since it was originally a convolution. the integral is actually a function on its own as a function of t (0 to t1, 0 to t2 etc). I am trying to avoid the convolution since it is the discrete version and requires scaling by the spacing (the spacing of my time points is not linear).
Any help would be appreciated. Let me know if anything needs clarification.

#### 0 Comments

Sign in to comment.

## 1 Answer ### Star Strider (view profile)

Answer by Star Strider

### Star Strider (view profile)

on 2 Nov 2015

How did you define your ‘Cpt’ function?
Where did you define it (anonymous function or its own function file)?

thatguy14

### thatguy14 (view profile)

on 2 Nov 2015
Yea I just realized I had forgot to define it as a anonymous function. That would fix it but I don't quite think that it will work how I want it to anyways... I may have to rethink this.

Sign in to comment.