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

1 visualización (últimos 30 días)
동주
동주 el 5 de Dic. de 2022
Respondida: Dyuman Joshi el 5 de Dic. de 2022
%% 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!

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 5 de Dic. de 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

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by