Problems plotting an implicit solution to a differential equation

22 vues (au cours des 30 derniers jours)
Georg
Georg le 20 Juil 2025
Commenté : Georg le 20 Juil 2025
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...

Réponse acceptée

Torsten
Torsten le 20 Juil 2025
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 commentaire
Georg
Georg le 20 Juil 2025
Thanks. That's great (and more complicated than I would have guessed).

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 20 Juil 2025
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 commentaire
Georg
Georg le 20 Juil 2025
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.

Connectez-vous pour commenter.

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by