1
$\begingroup$

I'm trying to find the transform of the following function using MATLAB:

$2x’’+x’-x = 27\cos(2t) +6 \sin(t)$

$x(0) = -1$ and $x’(0) = -2$

This is the code I have:

code

I keep getting a warning message in matlab saying"Character vector inputs are not recommended...". Can you tell me why this message is coming up and where I'm going wrong with my code?

  • 1
    Try: http://www.math.ucsd.edu/~bdriver/21d-f99/laplace_transform/9__laplace_transform.htm and http://terpconnect.umd.edu/~petersd/246/matlablaplace.html and https://www.rgnpublications.com/journals/index.php/jims/article/viewFile/284/2592017-02-25
  • 1
    Thanks Moo, I will check out those links.2017-02-25

1 Answers 1

1

The standard flow looks more or less like this:

syms t s Y
% Find Laplace transform of right-hand side.
RHS = laplace(27*cos(2*t)+6*sin(t));
% Find transforms of first two derivatives using
% initial conditions y(0) = -1 and y'(0) = -2.
Y1 = s*Y + 1;
Y2 = s*Y1 + 2;
sols = solve(2*Y2 + Y1 - Y - RHS, Y);
solt = ilaplace(sols,s,t);
pretty(solt)
fplot(solt,[0,8])
grid on

You can verify that solt is a particular solution of your differential equation. You can also check that it satisfies the initial conditions.

isAlways(2*diff(solt,t,2)+diff(solt,t)-solt == 27*cos(2*t)+6*sin(t)) % ans = 1
subs(solt, t, 0) % ans = -1
subs(diff(solt), t, 0) % ans = -2

Back in the day MATLAB had no support for function handles; an often-used workaround was to pass strings around with expressions to be evaluated, but now this practice is discouraged.