Problems plotting an implicit solution to a differential equation

18 visualizaciones (últimos 30 días)
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...

Respuesta aceptada

Torsten
Torsten el 20 de Jul. de 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

Más respuestas (1)

Walter Roberson
Walter Roberson el 20 de Jul. de 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 comentario
Georg
Georg el 20 de Jul. de 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.

Iniciar sesión para comentar.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by