# Numerical Integration in Matlab

조회 수: 1(최근 30일)
Raj Patel 2020년 12월 1일
댓글: Raj Patel 2020년 12월 1일
Hi guys,
I am trying to numerical integrate a function, but I am not able to do it correctly. Can anyone help me here? I think I am not writing the syntax correctly. I have attached the code below.
kb = 1.38 .* 10.^-23;
h = 1.05 .* 10.^-34;
n_puc = 1.81 .* 10.^19;
g = 5.2 .* 10.^-7;
B1 = 4.5 .* 10.^-20;
B2 = 410;
k_max = sqrt(4.* pi .* n_puc);
w_max = g .* k_max .* k_max;
T = 300;
c = (h.^2 ./ (2 .* pi .* kb .* T.^3 .* B1 .* exp(-B2 ./ T)));
% Integral:
fun = @(x) ((x .* exp((h .* x) ./ (kb .* T))) ./ (((exp((h .* x) ./ (kb .* T)) - 1).^2)));
K = c .* integral(fun,0,w_max);
Raj.

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

### 채택된 답변

Jim Riggs 2020년 12월 1일
편집: Jim Riggs 2020년 12월 1일
There seem to be two problems:
1) your function "fun" returns "NaN" at zero, so you cannot integrate starting from zero. You need to start from some non-zero value
2) I still get an error due to the integral function not being able to satify the tolerance. use the 'Relto' argument to reduce the tolerance, e.g.
xstart = 0.1;
D = integral(fun,xstart,w_max,'Relto',1e-3);
The problem I am seeing now is that the function is basically infinite at zero, therefore the integral value is highly dependent on the starting value. But the smaller you make the starting value, the larger you must make the Reltol in order to get a solution, so the numerical process is inherently limited.
##### 댓글 수: 1표시숨기기 없음
Raj Patel 2020년 12월 1일
Thanks Jim.

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

### Community Treasure Hunt

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

Start Hunting!