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

8 次查看(过去 30 天)
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

回答(1 个)

David Hill
David Hill 2022-12-5
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 个评论
Torsten
Torsten 2022-12-5
编辑:Torsten 2022-12-5
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by