Why does the solution contain the c1 variable even though I set the conditions?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
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)
fplot(ySol);
3 commentaires
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)
C1 = solve(limit(ySol,x,0)==0,var(2));
ySol = subs(ySol,var(2),C1);
figure(2)
fplot(ySol)
grid on
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!