Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: differential equation with piecewise function
Replies: 1   Last Post: May 26, 2014 3:34 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Christopher Creutzig

Posts: 274
Registered: 2/24/09
Re: differential equation with piecewise function
Posted: May 26, 2014 3:34 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 05.05.14 08:29, Matt wrote:
> hi,
> i need to solve the following differential equation
> x''+x=f(t)
> where x(0)=1, x'(0)=0 and
> f(t)= 3, 0<=t<4
> 2t-4, t>=4
> so in matlab, i defined a new function for f(t):
>
> function y=f(t)
> y=zeros(size(t));
> if 0<=t && t<=4
> y=3;
> elseif t>=4
> y=2*t-4;
> end
> end
>
> then i did the dsolve command as below:
>
> x=dsolve('D2x+x=y','x(0)=1', 'Dx(0)=0', 't')


dsolve called with strings knows nothing about MATLAB functions you've
defined anywhere.

In your case, the simplest way of solving the problem probably is to ask
for solutions on the two regions separately, using the solution from the
first interval to find the initial values at t=4 for the second interval:

>> syms x(t)
>> Dx(t) = diff(x);
>> x1(t) = dsolve(diff(x,t,t) + x == 3, x(0) == 0, Dx(0) == 0, t)


x1(t) =

3 - 3*cos(t)

>> Dx1(t) = diff(x1, t);
>> x2(t) = simplify(dsolve(diff(x,t,t) + x == 2*t-4, ...

x(4) == x1(4), Dx(4) == Dx1(4), t))

x2(t) =

2*t - cos(t - 4) - 2*sin(t - 4) - 3*cos(t) - 4


HTH,

Christopher




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.