フィルターのクリア

Solving 2nd Order Differential Equation Symbolically

80 ビュー (過去 30 日間)
Jordan Stanley
Jordan Stanley 2022 年 4 月 15 日
編集済み: Jordan Stanley 2022 年 4 月 16 日
Hello,
I have the 2nd order differential equation: y'' + 2y' + y = 0 with the initial conditions y(-1) = 0, y'(0) = 0.
I need to solve this equation symbolically and graph the solution.
Here is what I have so far...
syms y(x)
Dy = diff(y);
D2y = diff(y,2);
ode = D2y + 2*Dy + y == 0;
ySol = dsolve(ode,[y(-1)==0,Dy(0)==0])
a = linspace(0,1,20);
b = eval(vectorize(ySol));
plot(a,b)
But I get the following output.
ySol =
Error using eval
Unrecognized function or variable 'C1'.
I'd greatly appreciate any assistance.

採用された回答

Star Strider
Star Strider 2022 年 4 月 15 日
The constants are the initial condition. They must be defined.
syms y(x) y0
Dy = diff(y);
D2y = diff(y,2);
ode = D2y + 2*Dy + y == 0;
ySol(x,y0) = dsolve(ode,[Dy(0)==0,y(-1)==0,y(0)==y0])
ySol(x, y0) = 
% a = linspace(0,1,20);
% b = eval(vectorize(ySol));
figure
fsurf(ySol,[0 1 -1 1])
xlabel('x')
ylabel('y_0 (Initial Condition)')
.
  16 件のコメント
Torsten
Torsten 2022 年 4 月 16 日
編集済み: Torsten 2022 年 4 月 16 日
How should it be possible to solve 1. without 2. ? If you don't know the solution, you can't trace a solution curve. Or what's your opinion ?
Anyhow - I think your instructors overlooked that the equation together with its initial conditions does not only give one curve, but infinitly many. So "graphing the solution" will become difficult. But Star Strider's answer for this situation looks fine for me.
But you say you get an error. What's your code and what's the error message ?
Jordan Stanley
Jordan Stanley 2022 年 4 月 16 日
編集済み: Jordan Stanley 2022 年 4 月 16 日
Well I should mention that we were supposed to choose a 2nd order differential eqaution initial value problem from our textbook and maybe I just happened to choose a more complicated eqaution to use.
Ok, well interestingly enough upon running the code agin that Star Strider suggested I did not get an error message this time.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by