Matrix Dimensions must agree using integral
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
atsprink
2018 年 2 月 21 日
3 件のコメント
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
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!