Please help me to solve this simple error

10 ビュー (過去 30 日間)
T K
T K 2025 年 10 月 12 日
編集済み: Torsten 2025 年 10 月 12 日
%Code
% Tanh–Coth Method for Solving Nonlinear ODEs
clear; clc; syms U(xi) a0 a1 a2 b1 b2 c xi d1 d2 d3
% Example ODE: U'' - U + 2*U^3 = 0
ode = diff(U, xi, 2)*U^2 +(diff(U, xi, 1))^2*(2*U+1)+d1*U^4+d2*U^3;
% Step 1: Assume tanh–coth solution (up to order 2 for example)
U_trial = a0 + a1*tanh(d3*xi) + a2*tanh(d3*xi)^2 + b1*coth(d3*xi) + b2*coth(d3*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(d3*xi), coth(d3*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 d3], 'IgnoreAnalyticConstraints', true);
disp('Solutions for coefficients:')
disp(sol)

回答 (2 件)

Walter Roberson
Walter Roberson 2025 年 10 月 12 日
You have an installation error; somehow the implementing function (class actually) for sym has become a script instead of a function. You will need to reinstall the Symbolic Toolbox.
Your ode contains a single function, so eqns ends up containing a single equation. But you try to solve() that equation for 8 variables. solve() ends up hunting for degenerate solutions, combinations of variables that solve the entire equation at the same time; that takes a long time and is unlikely to succeed.
  1 件のコメント
Tarek
Tarek 2025 年 10 月 12 日

Thank you

サインインしてコメントする。


Torsten
Torsten 2025 年 10 月 12 日
編集済み: Torsten 2025 年 10 月 12 日
@Walter Roberson answered the question about your MATLAB error.
Concerning the problem you try to solve:
I assume d1, d2 are not equal to 0.
"ode_sub" is a polynomial in tanh(d3*xi) and coth(d3*xi) of degree 8. In order to make it satisfy the ode, you will have to find a0 a1 a2 b1 b2 d3 such that 16 coefficients (8 in front of tanh(d3*xi) and 8 in front of coth(d3*xi)) become 0. Thus you have a system of 16 equations in 6 free parameters. The system is overdetermined - there will hardly be a solution.
Of course, U identically 0 (thus a0 a1 a2 b1 b2 all equal to 0) solves the ode. But I doubt this is a solution you are looking for.
  1 件のコメント
Tarek
Tarek 2025 年 10 月 12 日

Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by