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

1 回表示 (過去 30 日間)
Marek
Marek 2022 年 12 月 5 日
コメント済み: David Hill 2022 年 12 月 5 日
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
David Hill
David Hill 2022 年 12 月 5 日
Excellent. Thanks for the correction.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by