Error using integral (line 85) A and B must be floating point scalars
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have a function below. I have successfully integrated it when the value of d=0.5. However, I want to integrate it for d= 5*10^-6, d=5*10^-5..... . I don't want to change the data points manually and do the integration. I want to define d as a vector and save the final result of the integration as well. When I try to do so I got Matlab error of "Error using integral (line 85) A and B must be floating point scalars."
Any help is appreciated.
clear all clc format long
% definition of constants
% d= 5*10^-1;
d=linspace(5*10^-6,5*10^-3,100);
q=1.6*10^(-19);
k=1.38*10^(-23);
Lb= 44*10^-6;
phi=90*10^-3;
T=293;
f = @(x) (4*k*T/q)*( atanh(tanh(q*phi/(4*k*T))*exp(-x/Lb)) + atanh(tanh(q*phi/(4*k*T))*exp(-(2*d-x)/Lb)));
fun=@(x) 1./(cosh(q.*f(x)./(k*T)));
rho_ap= (2./d).*integral(fun,0,d./2);
댓글 수: 0
채택된 답변
Star Strider
2017년 3월 13일
It is not obvious to me what you want to do. I would not use a vector for ‘d’ if you only need to evaluate your integral at 2 values of ‘d’.
See if this does what you want:
dv = [5E-6 5E-3];
q=1.6E-19;
k=1.38E-23;
Lb= 44E-6;
phi=90E-3;
T=293;
f = @(x,d) (4*k*T/q)*( atanh(tanh(q*phi/(4*k*T))*exp(-x/Lb)) + atanh(tanh(q*phi/(4*k*T))*exp(-(2*d-x)/Lb)));
fun=@(x,d) 1./(cosh(q.*f(x,d)./(k*T)));
for k1 = 1:length(dv)
rho_ap(k1) = (2./d(k1)).*integral(@(x) fun(x,dv(k1)), 0, dv(k1)/2);
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!