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
0 个评论
回答(1 个)
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)
fplot(ySol);
3 个评论
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)
C1 = solve(limit(ySol,x,0)==0,var(2));
ySol = subs(ySol,var(2),C1);
figure(2)
fplot(ySol)
grid on
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!