Problems plotting an implicit solution to a differential equation

5 visualizzazioni (ultimi 30 giorni)
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...

Risposta accettata

Torsten
Torsten il 20 Lug 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

Più risposte (1)

Walter Roberson
Walter Roberson il 20 Lug 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 Commento
Georg
Georg il 20 Lug 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.

Accedi per commentare.

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by