Complications when solving ODE's using heaviside functions as inputs (right hand sides)

2 views (last 30 days)
I have written a code to solve ODE's using the laplace method which works for normal inputs however when inputting a heaviside function for example -> 1 - heaviside(t-2) the results seem close to real answers however they are simplified in a way that is abstract relative to text book answers and answers done by me on paper. Yes I have tried the simplify() function and it proves to be a useless solution. I am asking if someone could take the challange to help me fix this code or at least give me an explanation of what happens with the heaviside() and or laplace() function "under the hood" please.
The code is below and I would encourage you try it and see for yourself what I am talking about.
An example question is:
syms s t Y;
disp(" ");
disp("For this code, Y is the function");
disp("Y1 is the first derivative");
disp("Y2 is the second derivative");
disp("F is the righthand side of the equation");
disp("E.G input for Eqn to solve -> Y2 + 2*Y1 - 3*Y - F")
disp(" ");
% Define the right hand side of the equation
f=input("Enter the right hand side of the equation: ");
% Takes the laplace of the right hand side and stores in "F"
F=laplace(f,t,s);
% Define the initial conditions
Yof0=input("Enter the value for Y(0): ");
Yprimeof0=input("Enter the value for Y'(0): ");
% Takes laplace of the first derivative function
Y1=s*Y-Yof0;
% Takes laplace of the second derivitave function
Y2 = s*Y1-Yprimeof0;
% Takes the desired equation to solve in terms of
% Y1 Y2 and F aka the right hand side
eqn=input("Enter the equation to solve: ");
% Now to solve in terms of laplace or "s"
s_ans = solve(eqn,Y);
% now to solve in terms of the time domain or "t"
t_ans = ilaplace(s_ans,s,t);
% Creates a space to make answers more readable
disp(" ");
% Now to output both answers
disp("The answer in the laplace domain is:");
disp(s_ans);
disp("The pretty answer is:");
pretty(s_ans);
disp("the answer in the time domain is:");
disp(t_ans);
disp("The pretty answer is:");
pretty(t_ans);
% Must always give thanks :)
disp("Fight the Quarantine!!!");

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!