Problems plotting an implicit solution to a differential equation

24 ビュー (過去 30 日間)
Georg
Georg 2025 年 7 月 20 日
コメント済み: Georg 2025 年 7 月 20 日
I am trying to plot the implicit solution to a differential equation, but fimplicit comes up with an error. The code is
clear all
syms y(x)
eqn = diff(y) == (2*x+y+2)/(2*x+y-4);
solutions = dsolve(eqn,Implicit=true)
solutions = 
impl = subs(solutions(1),[sym("C1"),x],[0,x])
impl = 
fimplicit(impl)
Warning: Error in state of SceneNode.
Unable to convert symbolic expression to double array because it contains symbolic function that does not evaluate to number. Input expression must evaluate to number.
The solution to the differential equation is correct. I am afraid I don't understand the error message for fimplicit...

採用された回答

Torsten
Torsten 2025 年 7 月 20 日
For more complicated cases where an explicit solution cannot be found:
syms y(x)
eqn = diff(y) == (2*x+y+2)/(2*x+y-4);
solutions = dsolve(eqn,Implicit=true)
solutions = 
syms u
impl1 = subs(lhs(solutions(1))-rhs(solutions(1)),[sym("C1"),y],[0,u]);
[impl2,~] = numden(lhs(solutions(2)));
impl2 = subs(impl2,y,u);
impl1 = matlabFunction(impl1,'Vars',[x,u])
impl1 = function_handle with value:
@(x,u)u-x-log(u+x.*2.0-2.0).*2.0+2.0
impl2 = matlabFunction(impl2,'Vars',[x,u])
impl2 = function_handle with value:
@(x,u)u+x.*2.0-2.0
hold on
fimplicit(impl1)
fimplicit(impl2)
hold off
grid on
  1 件のコメント
Georg
Georg 2025 年 7 月 20 日
Thanks. That's great (and more complicated than I would have guessed).

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 7 月 20 日
syms y(x)
eqn = diff(y) == (2*x+y+2)/(2*x+y-4);
solutions = dsolve(eqn,x)
solutions = 
impl1 = subs(solutions(1),[sym("C1"),x],[0,x])
impl1 = 
impl2 = solutions(2)
impl2 = 
fplot([impl1, impl2], [1 3.5])
  1 件のコメント
Georg
Georg 2025 年 7 月 20 日
The problem with the explicit answer is that it is only plotted up to the point where the tangent becomes vertical. I was suspecting that it continues on, and Torsten's answer above shows that.

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

カテゴリ

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

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by