필터 지우기
필터 지우기

Matrix Dimensions must agree using integral

조회 수: 2 (최근 30일)
atsprink
atsprink 2018년 2월 21일
편집: Torsten 2023년 2월 23일
Hello all,
I am trying to integrate over a function.
% calculation of f(b)
b = exp((-q*Vj)/(2*kB*Temp))*cosh((Et-Ei)/((kB*Temp)+0.5*(log(tau_p0/tau_n0))));
% integrate over x while varying b
fcn_b = zeros(1,length(b));
fcn = @(x)1./((x.^2)+(2.*b.*x)+1);
fcn_b = integral(fcn,0,Inf);
end
But I receive an error after the fcn = @x line saying matrix dimensions must agree.
The size of b => 1 x 141. Any help would be appreciated.
  댓글 수: 2
KSSV
KSSV 2018년 2월 21일
편집: KSSV 2018년 2월 21일
Give us the complete code......what is q? what is size of x?
atsprink
atsprink 2018년 2월 21일
편집: atsprink 2018년 2월 21일
All of those values are just constants except Vj. Vj is an array of 1 x 141. x is not a size, its a function of x as in f(x) = Integration of 1 / (x^2 + 2bx + 1) I uploaded all the files. Start with main.m
edit: added too many files.... comment out lines 10-19 in main.m as those function calls are not needed

댓글을 달려면 로그인하십시오.

채택된 답변

atsprink
atsprink 2018년 2월 21일
I figured it out I believe. I needed to add " 'ArrayValued', true " to my integral fcn_b line of code. It is at least not throwing an error right now but not sure if it is returning a correct answer.
  댓글 수: 3
Lucas Ivan
Lucas Ivan 2023년 2월 23일
Hello everyone! I was having the same error and I could solve it with this. However, any idea on why we need to add this argument?
Torsten
Torsten 2023년 2월 23일
편집: Torsten 2023년 2월 23일
However, any idea on why we need to add this argument?
If you don't add this argument, MATLAB calls your function to be integrated with a vector of values for the integration variable and expects your function to return a vector of the same size. This won't happen since your function itself is a vector of functions - depending on the vector b. If you set "ArrayValued" to "true", MATLAB "knows" that you want to integrate a vector-valued function and calls it only with single (scalar) values for the integration variable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by