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
Daniel kiracofe
2016년 11월 13일
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
2016년 11월 13일
채택된 답변
추가 답변 (1개)
Roger Stafford
2016년 11월 13일
편집: Roger Stafford
2016년 11월 13일
0 개 추천
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
Emily Takeva
2016년 11월 13일
Roger Stafford
2016년 11월 14일
Did you transpose tau as I specified using tau.'?
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!