フィルターのクリア

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

1 回表示 (過去 30 日間)
friet
friet 2017 年 3 月 13 日
コメント済み: Star Strider 2017 年 3 月 13 日
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);

採用された回答

Star Strider
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
  2 件のコメント
friet
friet 2017 年 3 月 13 日
Thanks Star Strider ! That actually solve my problem!
Star Strider
Star Strider 2017 年 3 月 13 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by