dsolve problem not showing result

3 ビュー (過去 30 日間)
Raghuraman S
Raghuraman S 2019 年 2 月 14 日
編集済み: madhan ravi 2019 年 2 月 14 日
I was trying to solve a simple diffrential equation solving dy/dx =y/x and plot curves using different initial value conditions.
Please refer attached picture file, the script throws erros, where as the dsolve function in the command prompt gives the right answer. Matlab code is attached as well. When I change dy/dx = cos(x) or y+x even script works fine.
Sure,I am missing something, usual some help is appreciated.

採用された回答

madhan ravi
madhan ravi 2019 年 2 月 14 日
編集済み: madhan ravi 2019 年 2 月 14 日
syms y(x)
eqn = diff(y) == y/x;
vars = y(x);
V = odeToVectorField(eqn)
M = matlabFunction(V,'vars', {'x','Y'})
interval = [0 pi]; %x interval
for y0=-3:4 %initial conditions
[x,ysol]=ode45(M,interval,y0);
plot(x,ysol)
hold on
end
grid on
ysol
  2 件のコメント
madhan ravi
madhan ravi 2019 年 2 月 14 日
Just convert your symbolic ode to numerical ode and then plot the solutions.
Raghuraman S
Raghuraman S 2019 年 2 月 14 日
編集済み: madhan ravi 2019 年 2 月 14 日
Thanks Madhan,
But I got the real problem, I gave y(0) as initial condition in script, which means the solution is always "zero". This was the case in script. When typed in command prompt, I sought general solution where dsolve gave the right result.
In the script when I entered y(1) etc, the solution is just fine. How silly of me!!!!
Anyways, appreciate your reply.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by