I want make a (t,h)graph. But I can 't solve a problem ㅜㅜ.

1 回表示 (過去 30 日間)
동주
동주 2022 年 12 月 5 日
回答済み: Dyuman Joshi 2022 年 12 月 5 日
%% Time it takes for the cylinder to drain.
clear
f=@(H) 1/sqrt(H);
a=0.0001;
b=10:0.1:20;
n=16;
h=(b-a)./n;
so=0;
se=0;
for k=1:1:n-1
x1=a+k*h;
y=1/sqrt(x1);
if rem(k,2)==1
so=so+y1;%sum of odd terms
else
se=se+y1; %sum of even terms
end
end
Ans=h./3*(f(a)+f(b)+4*so+2*se);
d=0.1; D=1;
t =(D/d)^2 * (1/(2*9.81)^1/2)*Ans;
plot(b,t ), grid on
please check my script!

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 12 月 5 日
- y1 is not defined in the code
- If you want to perform vector operation using function handle, use element wise operations
f=@(H) 1./sqrt(H);
%^
a=0.0001;
b=10:0.1:20;
n=16;
h=(b-a)./n;
so=0;
se=0;
for k=1:n-1
x1=a+k*h;
y=1/sqrt(x1); %check the formula
if rem(k,2)==1
so=so+y1;%sum of odd terms
else
se=se+y1; %sum of even terms
end
end
val=h./(3*(f(a)+f(b)+4*so+2*se));
d=0.1; D=1;
t =(D/d)^2*(1/(2*9.81)^1/2)*val;
plot(b,t)
grid on

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by