Numerical Integration In Matlab
1 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!