Double integral error Matrix dimensions must agree
Afficher commentaires plus anciens

I have a problem with computing a double integral. My code so far is:
B = 5;
L0 = 0:10;
A0 = 0:10;
tau = 1:100;
% Open and read the file
fid = fopen('first.txt', 'r');
data = cell2mat(textscan(fid, '%d'));
data = dlmread('first.txt');
% Two columns in the file
% First corresponds to time
t = data(:,1);
% Second to data values for luminosity
d = data(:,2);
% Posteriors for the three models 0,1&2
p0 = ((1./sqrt(2.*pi))^10).*(exp(-sum(0.5.*(d-B).^2)));
p1 =@(L0)((1./sqrt(2.*pi))^10).*(exp(-sum(0.5.*(d-B-L0).^2)));
p2 = @(A0,tau)((1./sqrt(2.*pi))^10).*(exp(-sum(0.5.*(d-B-A0.*exp(-t/tau)).^2)));
I1 = integral (p1, 0,10);
I2 = integral2 (p2,0, 10, 1, 100);
fclose(fid);
It seems to work fine for the normal integral I1 but crashes for the double integral I2. Any suggestions? ps. Sorry for the long equations
In the file, I have this:
0 7.108842
1 5.360705
2 5.871565
3 4.441087
4 6.877640
5 6.049399
6 5.587317
7 6.687828
8 7.390521
9 5.646180
2 commentaires
Daniel kiracofe
le 13 Nov 2016
Suggest that you post the actual error message and the first.txt data file. "crashes" is not very descriptive, and without the data we cannot try the code.
Emily Takeva
le 13 Nov 2016
Réponse acceptée
Plus de réponses (1)
Roger Stafford
le 13 Nov 2016
Modifié(e) : Roger Stafford
le 13 Nov 2016
0 votes
1. In the expression for ‘p2’ you have “t/tau” which is matrix division. However the sizes of ’t’ and ‘tau’ are incompatible with matrix division. Probably you need -t./tau.’ . (That's a transpose operator on tau to make it a column vector.)
2. I also have serious doubts about the validity of taking the sum in calculating both ‘p1’ and ‘p2’. It makes a very strange kind of integrand. You are already summing over your data in obtaining each individual integrand value as ‘L0’ and ‘A0’ vary.
3. Also why did you define ‘L0’ and ‘A0’ as vectors earlier, while using the same symbols for arguments in ‘p1’ and ‘p2’? It suggests some kind of erroneous thinking in 2. above.
2 commentaires
Emily Takeva
le 13 Nov 2016
Roger Stafford
le 14 Nov 2016
Did you transpose tau as I specified using tau.'?
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!