フィルターのクリア

Zeros from Trapz integration

7 ビュー (過去 30 日間)
Brittany Burns
Brittany Burns 2022 年 4 月 20 日
編集済み: Torsten 2022 年 5 月 17 日
I'm trying to solve for Tstar via integration of Dm; however, I keep getting all zeroes. How should I be using trapz? Is it better to use another command?
clear all;clc
%Given
TL=300; %surface T [K]
alpha=4/1000^2; %Thermal diffusivity [m^2/s]
L=2; %thickness [m]
x=0:0.01:L; %[m]
xstar=x/L;
t=[0 2 20 200]*3600; %time [s]
tstar=(alpha.*t)/L^2;
%Temperatures
T0x0=340;%T0(x=0)
T0x=-182.22.*x.^3 + 582.22.*x.^2 - 445.56.*x + 340; %To(x)
T0star = (T0x - TL)./(T0x0 - TL); %T0 star
for k = 1:length(t)
for i = 1 : length(x)
lambda(i) = ((2*i - 1)*pi) / 2;
fun(i,k)=T0star(i).*cos(lambda(i).*xstar(i));
Dm(i,k)=trapz(fun(i,k),0,1);
Tstar(i,k)=Dm(i,k)*cos(lambda(i)*xstar(i))*exp(-(lambda(i))^2*tstar(k));
end
end
  2 件のコメント
KSSV
KSSV 2022 年 4 月 20 日
Dm(i,k)=trapz(fun(i,k),0,1);
In the above line fun(i,k) is a single, number, how you expect to get area?
John D'Errico
John D'Errico 2022 年 5 月 17 日
It looks like you think that trapz is a tool that can do intgration over an interval. For example you call trapz with THREE arguments. For example, when I do this:
trapz(5,0,1)
ans = 0
As you should see, trapz returns zero. Why? trapz is not integrating the constant function with value 5, over the interval [0,1]. Instead, what you did just misuses trapz. Read the help for trapz. Look at the examples of use.

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

回答 (1 件)

Torsten
Torsten 2022 年 5 月 17 日
編集済み: Torsten 2022 年 5 月 17 日
Maybe you mean something like
L = 2; %thickness [m]
TL = 300; %surface T [K]
T0x0 = 340;%T0(x=0)
T0x = @(x) -182.22.*x.^3 + 582.22.*x.^2 - 445.56.*x + 340;
T0star = @(x) (T0x(x) - TL)./(T0x0 - TL); %T0 star
fun = @(x,i) T0star(x).*cos((2*i-1)/2 * pi * x/L);
x = 0:0.01:L; %[m]
I = 1:numel(x);
value = arrayfun(@(i)integral(@(x)fun(x,i),0,L),I)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by