About Solving nonlinear ODE

2 vues (au cours des 30 derniers jours)
WooJin Choi
WooJin Choi le 8 Août 2021
Modifié(e) : Animesh le 23 Fév 2024
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 commentaire
darova
darova le 8 Août 2021
quadratic equation of this type has 2 roots:
Maybe you need to solve it using discriminant and choose some root

Connectez-vous pour commenter.

Réponses (1)

Animesh
Animesh le 23 Fév 2024
Modifié(e) : Animesh le 23 Fév 2024
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:

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by