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 CenterFile Exchange에서 Numerical 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