Solving First order ODE with constant coefficient
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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)])
0 Kommentare
Antworten (1)
Bjorn Gustavsson
am 1 Aug. 2021
Bearbeitet: Bjorn Gustavsson
am 1 Aug. 2021
Should be as simple as:
sym y(t)
Also: isn't direct use of dsolve enough for you?
HTH
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!