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

1 view (last 30 days)
%% 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!

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 5 Dec 2022
- 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

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!