About Solving nonlinear ODE
2 次查看(过去 30 天)
显示 更早的评论
I want to solve under nonlinear ODE.
A1*diff(y,t) - A2*(2*g*y + diff(y,t)^2)^(1/2) = K1
and constants are A1 = 78, A2 = 0.0081, g = 9.8, K1 = 0.025 and initial condition is y(0) == 9
I coded
syms y(t)
ode = A1*diff(y,t) - A2*(2*g*y + diff(y,t)^2)^(1/2) == K1 ;
cond = y(0) == 9 ;
ySol(t) = dsolve (ode, cond)
but mathlab couldn't solve this problem, so I transformed equation,
((A1^2) - (A2^2))*(diff(y,t))^2 - 2*A1*K1*diff(y,t) - (A2^2)*2*g*y + K1^2 =0
that I shifted K1 to the left side and A2*(2*g*y + diff(y,t)^2)^(1/2) to the right side, and squared them.
then I coded
syms y(t)
ode = ((A1^2) - (A2^2))*(diff(y,t))^2 - 2*A1*K1*diff(y,t) - (A2^2)*2*g*y + K1^2 == 0 ;
cond = y(0) == 9 ;
ySol(t) = dsolve (ode, cond)
matlab solved the problem, but solution was not that i wanted. (solution equation included lambert function etc)
I thought the solution would be quadratic function.
Help me, please and thak you for your answer.
1 个评论
darova
2021-8-8
quadratic equation of this type has 2 roots:
Maybe you need to solve it using discriminant and choose some root
回答(1 个)
Animesh
2024-2-23
编辑:Animesh
2024-2-23
Hey @WooJin Choi
Seems like you are trying to solve nonlinear ODE given by “A1*diff(y,t) - A2*(2*g*y + diff(y,t)^2)^(1/2) = K1” for a quadratic solution.
The presence of Lambert function in the solution indicates that the solution to this equation is more complex than a simple quadratic equation.
In the given ODE, the term “dy/dt” appears both linearly and inside a square root, and moreover, it is not the only term inside the square root. The presence of “y” inside the square root along with “dy/dt” significantly complicates the solution. This means that we cannot move the terms around to obtain a quadratic equation in “dy/dt”.
Therefore, the nonlinearity and the structure of the ODE prevent us from reducing it to a quadratic form that can be solved analytically using the quadratic formula.
Although we can consider numerical methods to approximate the solution for the given ODE. To solve this equation numerically, we need to reformulate it so that it can be handled by MATLAB's numerical solvers, which require the derivative to be isolated on one side of the equation. Since we cannot isolate “dy/dt” due to the square root, we can instead use a root-finding approach at each time step to determine “dy/dt”
Here is a MATLAB script that uses “fsolve” to find “dy/dt” and then employs a simple numerical integration technique to approximate the solution over a time span:
function dydt = solveForDerivative(t, y, A1, A2, g, K1, dydt_guess)
% Define the function for which we want to find the root
func = @(dydt) A1*dydt - A2*sqrt(2*g*y + dydt^2) - K1;
% Use a root-finding method like fsolve to find dydt
options = optimoptions('fsolve', 'Display', 'none'); % Suppress fsolve output
dydt = fsolve(func, dydt_guess, options);
end
A1 = 78;
A2 = 0.0081;
g = 9.8;
K1 = 0.025;
% Define initial conditions and time span
y0 = 9;
dydt_guess = 0; % Initial guess for dy/dt
% Define time points where we want the solution
t_points = linspace(0, 10, 100); % 100 time points from 0 to 10
y_values = zeros(size(t_points));
y_values(1) = y0; % Initial condition
% Perform a custom numerical integration
for i = 2:length(t_points)
% Current time
t = t_points(i);
y_prev = y_values(i-1);
% Calculate dy/dt using the custom ODE function
dydt = solveForDerivative(t, y_prev, A1, A2, g, K1, dydt_guess);
% Update the guess for the next iteration
dydt_guess = dydt;
% Estimate the new value of y using Euler's method (simplest integration method)
dt = t_points(i) - t_points(i-1);
y_values(i) = y_prev + dydt * dt;
end
plot(t_points, y_values);
xlabel('Time');
ylabel('y(t)');
title('Approximate numerical solution of the ODE');
Here, we have used Euler’s method for numerical integration, but you can go for more sophisticated methods like “runga-kutta” or MATLAB functions like “ode45” with custom iteration to handle non linearity.
Moreover, you can refer the following MathWorks documentations for more information:
- Solving a non linear ODE: https://www.mathworks.com/help/curvefit/solving-a-nonlinear-ode.html
- “fsolve” function: https://www.mathworks.com/help/optim/ug/fsolve.html
- Basic Solver Selection: https://www.mathworks.com/help/matlab/math/choose-an-ode-solver.html#:~:text=i*yv(%3A%2C2)%3B-,Basic%20Solver%20Selection,-ode45%20performs%20well
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!