Accuracy of integral function.
Show older comments
Hi
I am solving a long equation with q,k,phi,D are constants and x variable. I am using the the matlab keyword "integral" to integrate the equation. when I vary D from 10^-3 to 10^-5, I am supposed to get the final answer rho_ap vary from ~1 to ~0. However in my matlab code it gived my a fixed value of 1 when ever i vary D. Is the way i calculate my integration accurate. How accurate is integral function in matlab.

Thanks
clear all
clc
format long
% definition of constants
rho0=3*(10^11);
d= 1*10^-14;
q=1.6*10^(-19);
k=25*10^-3;
Lb= 44*10^-6;
phi=90*10^-3;
f = @(x) (4*k/q)*( atanh(tanh(q*phi/(4*k))*exp(-x/Lb)) + atanh(tanh(q*phi/(4*k))*exp(-(d-x)/Lb)));
fun=@(x) 1./(cosh(q.*f(x)./k));
rho_ap= (2/d)*integral(fun,0,d/2);
Accepted Answer
More Answers (1)
Roger Stafford
on 1 Mar 2017
I see an error. The line
f = @(x) (4*k/q)*( atan(tan(q*phi/4*k)*exp(-x/Lb))+ atan(tan(q*phi/4*k)*exp(-(d-x)/Lb)))
should be:
f = @(x) (4*k/q)*( atan(tan(q*phi/(4*k))*exp(-x/Lb))+ atan(tan(q*phi/(4*k))*exp(-(d-x)/Lb)))
You were multiplying by k rather than dividing by it.
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!