フィルターのクリア

How to solve 2nd ODE equation in numerical and analytical method at same plot graph?

1 回表示 (過去 30 日間)
Hello,
I am was looking for help to solve this equation
d^x/dt^2 + dx/dt + x =1
in Matlab, can I get help to solve this equation of plot the numerical solutions and analytical solutions in the same graph and compare them.
with ode45
can anyone help me with this code?

採用された回答

Star Strider
Star Strider 2022 年 9 月 28 日
Interesting problem!
I was curious enough to do the entire simulation to see what the results are —
syms x(t) x0 Dx0 T Y
Dx = diff(x);
D2x = diff(Dx);
DEqn = D2x + Dx + x == 1;
xs = dsolve(DEqn, x(0)==x0, Dx(0)==Dx0)
xs = 
xs = subs(xs, {x0,Dx0},{1,1}) % Numerical Initial Conditions
xs = 
[VF,Sbs] = odeToVectorField(DEqn)
VF = 
Sbs = 
DEfcn = matlabFunction(VF, 'Vars',{T,Y})
DEfcn = function_handle with value:
@(T,Y)[Y(2);-Y(1)-Y(2)+1.0]
tspan = [0 10];
[t,x] = ode89(DEfcn, tspan, [1 1]);
figure
fplot(xs, tspan, 'DisplayName','Analytic')
hold on
plot(t, x(:,1), 'DisplayName','Numeric')
hold off
grid
xlabel('Time')
ylabel('x_1(t)')
legend('Location','best')
They match almost exactly.
.
  4 件のコメント
Shreyas Sangamesh
Shreyas Sangamesh 2022 年 9 月 28 日
Okay perfect,
Thank you for assistance.
Star Strider
Star Strider 2022 年 9 月 28 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by