Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Math Forum
»
Discussions
»
Software
»
comp.softsys.matlab
Notice: We are no longer accepting new posts, but the forums will continue to be readable.
Topic:
differential equation with piecewise function
Replies:
1
Last Post:
May 26, 2014 3:34 AM




Re: differential equation with piecewise function
Posted:
May 26, 2014 3:34 AM


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 > 2t4, 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*t4; > 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*t4, ... 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



