Error using integral (line 85) A and B must be floating point scalars

1 Ansicht (letzte 30 Tage)
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);

Akzeptierte Antwort

Star Strider
Star Strider am 13 Mär. 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by