Numerical Integration In Matlab
7 ビュー (過去 30 日間)
古いコメントを表示
I need some help solving numerical integration.
The integral is:
fun = @(x) (x .* (exp(x) ./ (exp(x) - 1).^2) .* ((asind(0.0003 .* 1 .* x)).^2 ./ sqrt(1 - (0.0003 .* 1 .* x).^2))); Note: asind = sin^-1(....) --> (I am not sure if this is correct)
C = @(T) integral(fun, 0, 517.39 ./ T);
The limit of x is from: x = 0 to x = (500/T)
T ranges from (1 - 1000) (which is T = logspace(0, 3))
Can anyone help me solve this integral. I want to plot a loglog plot of (C as a function of T). I am getting some errors which I am not able to overcome.
Thanks in advance.
Raj.
0 件のコメント
採用された回答
Star Strider
2020 年 10 月 13 日
The integral function will produce one value for the specific limits of integration. To create a vector from its outputs, a loop is necessary.
Try this:
fun = @(x) (x .* (exp(x) ./ (exp(x) - 1).^2) .* ((asind(0.0003 .* 1 .* x)).^2 ./ sqrt(1 - (0.0003 .* 1 .* x).^2)));
T = logspace(0, 3);
C = @(T) integral(fun, 0, 517.39 ./ T);
for k = 1:numel(T)
Cint(k) = C(T(k));
end
figure
plot(T, Cint)
grid
.
10 件のコメント
Star Strider
2020 年 10 月 27 日
As always, my pleasure!
I thought we just solvedd that exact problem? I only posted the few lines that changed.
The full code is:
kb = 1.38 .* 10.^-23;
h = 1.05 .* 10.^-34;
wd = 6.94 .* 10.^13;
vs = 6084;
B1 = 2.7 .* 10.^-19;
B2 = 170;
A1 = 2 .* 10.^-45;
D = 0.004;
T = 300;
c = @(T) (h.^2 .* D) ./ (2 .* pi * pi * vs * kb .* T .* T);
fun = @(x,T) ((x.^4 .* exp((h.*x) ./ (kb .* T))) ./ (((exp((h.*x) ./ (kb .* T))-1).^2) .* ((D.*B1 .* x.^2 .* T .* exp(-B2/T)) + (D.*A1 .* x.^4) + vs)));
T = 1:1000;
for k = 1:numel(T)
K(k) = c(T(k)) .* integral(@(x)fun(x,T(k)),0,wd);
end
figure
plot(T, K)
grid
xlabel('T')
ylabel('K')
It produces the same plot, so I will not re-post it.
This also works (without the loop, using 'ArrayValued'):
c = @(T) (h.^2 .* D) ./ (2 .* pi * pi * vs * kb .* T .* T);
fun = @(x,T) ((x.^4 .* exp((h.*x) ./ (kb .* T))) ./ (((exp((h.*x) ./ (kb .* T))-1).^2) .* ((D.*B1 .* x.^2 .* T .* exp(-B2./T)) + (D.*A1 .* x.^4) + vs)));
T = 1:1000;
K = c(T) .* integral(@(x)fun(x,T),0,wd,'ArrayValued',1);
figure
plot(T, K)
grid
xlabel('T')
ylabel('K')
producing the same plot.
The ‘fun’ code changed slightly to make it fully vectorised.
.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!