Solving First order ODE with constant coefficient

20 ビュー (過去 30 日間)
Alexandra Reyes
Alexandra Reyes 2021 年 8 月 1 日
編集済み: Bjorn Gustavsson 2021 年 8 月 1 日
How do i fix y= sym('y(t)') as it always show error and could not run the program properly.
%%Solving First Order ODEs with constant coefficients
syms t s Y
y = syms('y(t)'); % writing y as a function of t
y1 = diff(y,t); % Derivative of y(t) in symbolic form
a = input('Enter the coefficient of dy/dt in the equation');
b = input('Enter the coefficient of y in the equation');
f = input('Enter the inhomogenous part of the equation');
y0 = input('The initial condition is y(0)-');
eqnt = a*y1 + b*y - f; % Differential equation in the form eqnt - 0
eqns = laplace (eqnt, s); %Taking Laplace Transform of the DE
eqns = subs(eqns, {'laplace (y(t), t,s)','y(0)'}, {Y,y0});
Y = simplify (solve(eqns, Y)); %Solving algebraic equation eqns - 0 for Y and simplifying
y = ilaplace (Y, s, t); %Taking inverse laplce transform of Y to get y
disp(['The solution of the differential equation is: y(t)', char(y)])

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 1 日
編集済み: Bjorn Gustavsson 2021 年 8 月 1 日
Should be as simple as:
sym y(t)
Also: isn't direct use of dsolve enough for you?
HTH

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by