Solving First order ODE with constant coefficient

조회 수: 6 (최근 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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by