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

1 次查看(过去 30 天)
%% 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