Problems plotting an implicit solution to a differential equation

22 Ansichten (letzte 30 Tage)
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...

Akzeptierte Antwort

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

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 20 Jul. 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 Kommentar
Georg
Georg am 20 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by