Why does the solution contain the c1 variable even though I set the conditions?

11 vues (au cours des 30 derniers jours)
Marek
Marek le 5 Déc 2022
Commenté : David Hill le 5 Déc 2022
I´m trying to plot the solution of the following differential equation but I keep getting the c1 variable restraining me from ploting the symbolic function with two variables
syms y(x)
ode = diff(y) == 2+y/x
cond = y(0) == 0
ySol = dsolve(ode,cond)
fplot(ySol);
The solution of dsolve is ySol = C1*x + 2*x*log(x)
According to documentation specifing the initial condition should find a value of c1 and find a solution without the constant but I keep getting solution with the constant. Thank you for help

Réponses (1)

David Hill
David Hill le 5 Déc 2022
Problem with y(0) condition (log(0) = -inf)
syms y(x)
ode = diff(y) == 2+y/x;
cond = y(.001) == 0;
ySol = dsolve(ode,cond)
ySol = 
fplot(ySol);
  3 commentaires
Torsten
Torsten le 5 Déc 2022
Modifié(e) : Torsten le 5 Déc 2022
Note the difference between the correct and the "approximate" solution.
syms y(x) x
ode = diff(y) == 2+y/x;
cond = y(.001) == 0;
ySol = dsolve(ode,cond);
ySol_correct = 2*x*log(x);
figure(1)
hold on
fplot(ySol)
fplot(ySol_correct)
hold off
grid on
First get the general solution - then insert your boundary condition:
syms y(x)
ode = diff(y) == 2+y/x;
ySol(x) = dsolve(ode);
var = symvar(ySol)
var = 
C1 = solve(limit(ySol,x,0)==0,var(2));
ySol = subs(ySol,var(2),C1);
figure(2)
fplot(ySol)
grid on
David Hill
David Hill le 5 Déc 2022
Excellent. Thanks for the correction.

Connectez-vous pour commenter.

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by