Info

This question is closed. Reopen it to edit or answer.

I need to find the values of the constants

75 views (last 30 days)
T K
T K on 8 Oct 2025 at 2:56
Closed: Walter Roberson on 12 Oct 2025 at 20:51
% Tanh–Coth Method for Solving Nonlinear ODEs
clear; clc; syms U(xi) a0 a1 a2 b1 b2 c xi
% Example ODE: U'' - U + 2*U^3 = 0
ode = U^2*diff(U, xi, 2)+diff(U,xi,1)*(2*U+1) + U^4+U^3;
% Step 1: Assume tanh–coth solution (up to order 2 for example)
U_trial = a0 + a1*tanh(xi) + a2*tanh(xi)^2 + b1*coth(xi) + b2*coth(xi)^2;
% Step 2: Substitute the trial function into the ODE
ode_sub = subs(ode, U, U_trial);
% Step 3: Expand and simplify
ode_simplified = simplify(expand(ode_sub));
% Step 4: Collect terms with respect to tanh and coth
% Convert to polynomial form in tanh(xi) and coth(xi)
ode_collected = collect(ode_simplified, [tanh(xi), coth(xi)]);
% Step 5: Equate coefficients of each power of tanh and coth to zero
% (To make the equation identically zero)
coeffs_tanh = coeffs(ode_collected, tanh(xi));
eqns = [];
for k = 1:length(coeffs_tanh)
eqns = [eqns, simplify(coeffs_tanh(k)) == 0];
end
% Step 6: Solve for coefficients
sol = solve(eqns, [a0 a1 a2 b1 b2 d1 d2], 'IgnoreAnalyticConstraints', true);
disp('Solutions for coefficients:')
disp(sol)
  2 Comments
Alexander
Alexander about 2 hours ago
Hey i see different issues here:
  • ode does not match the stated example. Make sure you’re solving the intended ODE.
  • U_trial mixed tanh and coth without reducing identities → derivatives introduce sech^2/csch^2 and you never eliminated them.
  • Try to prefer use one basis: e.g. tanh-only. If you keep coth, replace it with 1/tanh and multiply through by enough powers of tanh to clear denominators before collecting.
  • Try to "simplify(ode)" and after that to substitute "subs(ode, sech(k*xi)^2, 1 - tanh(k*xi)^2)"
  • solve(..., [a0 a1 a2 b1 b2 d1 d2]) referenced d1,d2 which you never declared?

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!