Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I need to find the values of the constants

75 ビュー (過去 30 日間)
T K
T K 2025 年 10 月 8 日 2:56
閉鎖済み: Walter Roberson 約19時間 前
% 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 件のコメント
Alexander
Alexander 約20時間 前
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?

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by