Double integral error Matrix dimensions must agree

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 Kommentare

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.
Hi Daniel, I included picture of the errors and the info in the file.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Emily Takeva
Emily Takeva am 14 Nov. 2016

0 Stimmen

I found what's wrong. Apparently, we can't use I1 and I2 when defining the integral. When I changed it to q1 and q2, it worked. I think it is something to do with I1 and I2 used somewhere else already.

Weitere Antworten (1)

Roger Stafford
Roger Stafford am 13 Nov. 2016
Bearbeitet: Roger Stafford am 13 Nov. 2016

0 Stimmen

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 Kommentare

1. I used./ and nothing changed in the errors.
2. It is a statistical expression to do with posterior probability and I'm positively sure it's correct.
3. I commented the defining of those and still nothing changes.
Did you transpose tau as I specified using tau.'?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by