How to solve this equation?
1 次查看(过去 30 天)
显示 更早的评论
Hey guys
How can I solve this simple ode equation with matlab??
1 个评论
Wan Ji
2021-8-23
Hi 金成勋 my friend,
This is a first-order nonlinear ode with power exponent other than 1, far more complicated than you ever imagine.
采纳的回答
Star Strider
2021-8-23
One approach —
syms h(t) t Y
Dh = diff(h);
Eqn = 25*pi*Dh == pi*(4*0.0254)^2 * sqrt(2*9.8*h*2*(101325/876)+Dh^2)+90/3600
Eqn = isolate(Eqn,Dh)
[VF,Subs] = odeToVectorField(Eqn)
VF = simplify(VF, 500)
hfcn = matlabFunction(VF, 'Vars',{t,Y})
Then use the appropriate numerical ODE solver (most likely ode15s) to integrate it.
.
5 个评论
Star Strider
2021-8-25
The equation itself does not have any parameters that can be estimated that would give a negative slope.
The sqrt term has both positive and negative roots, so change the sign of that term to get the negative square roots:
hfcnp = @(t,Y)[(pi.*8.112963841460668e+32+sqrt(7.3e+1).*sqrt(Y(1).*-1.129628243491514e+37+pi.^2.*Y(1).*6.713376166760685e+42+1.480615901066572e+33).*3.201062735323997e+12)./(pi.^2.*8.112963841460668e+35-1.365130281111817e+30)];
hfcnn = @(t,Y)[(pi.*8.112963841460668e+32-sqrt(7.3e+1).*sqrt(Y(1).*-1.129628243491514e+37+pi.^2.*Y(1).*6.713376166760685e+42+1.480615901066572e+33).*3.201062735323997e+12)./(pi.^2.*8.112963841460668e+35-1.365130281111817e+30)];
% ↑ ← HERE
tspan = [0 10];
ic = 0;
[tp,yp] = ode15s(hfcnp, tspan, ic);
[tn,yn] = ode15s(hfcnn, tspan, ic);
figure
yyaxis left
plot(tp, yp)
ylabel('h(t) +Root')
yyaxis right
plot(tn, yn)
grid
xlabel('t')
ylabel('h(t) -Root')
legend('Positive Root','Negative Root', 'Location','SE')
I doubt that it has a negative slope anywhere.
The only way to force that would be to negate the derivative:
% hfcnp = @(t,Y)-[(pi.*8.112963841460668e+32+sqrt(7.3e+1).*sqrt(Y(1).*-1.129628243491514e+37+pi.^2.*Y(1).*6.713376166760685e+42+1.480615901066572e+33).*3.201062735323997e+12)./(pi.^2.*8.112963841460668e+35-1.365130281111817e+30)];
% hfcnn = @(t,Y)-[(pi.*8.112963841460668e+32-sqrt(7.3e+1).*sqrt(Y(1).*-1.129628243491514e+37+pi.^2.*Y(1).*6.713376166760685e+42+1.480615901066572e+33).*3.201062735323997e+12)./(pi.^2.*8.112963841460668e+35-1.365130281111817e+30)];
% % ↑ ← HERE
%
% tspan = [0 10];
% ic = 0;
% [tp,yp] = ode15s(hfcnp, tspan, ic);
% [tn,yn] = ode15s(hfcnn, tspan, ic);
%
% figure
% yyaxis left
% plot(tp, yp)
% ylabel('h(t) +Root')
% yyaxis right
% plot(tn, yn)
% grid
% xlabel('t')
% ylabel('h(t) -Root')
% legend('Positive Root','Negative Root', 'Location','SE')
I cannot run that (the commented-out code) here because it times out, and even takes an extraordinarily long time on my computer when I run it offlline, so it may not have s solution.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!