0

I am looking for a way to include piecewise functions in the dsolve command in order to solve a 2nd order differential equation. Dsolve works fine if H(x),G(x),F(x) are constant, but I need them to become piecewise symbolic functions. Thanks.

(for example H(x)= 0.5 for (0<=x<0.5) and H(x)= 1 for (0.5<=x=<1))

syms U(x) g(x) H(x) F(x) G(x) x b
H(x)=1;
F(x)=0.02;
b=1;
G=0.15;
g(x)=dsolve(1000*9.81*H(x)*0.001-1000*F/8*g(x)+1000*0.07*H(x)*H(x)(F/8).^0.5*0.5*diff(g,2)==G,g(0)==0,g(b)==0)
U(x)= (g(x))^0.5
Amro
  • 123,847
  • 25
  • 243
  • 454
SuzieQ
  • 1
  • 1
  • 3
    related: http://stackoverflow.com/q/3687069/97160, http://math.stackexchange.com/q/868010/133, http://www.mathworks.com/matlabcentral/answers/124263-creating-a-piecewise-symbolic-function – Amro Apr 13 '16 at 18:37
  • I have already tried to use the HEAVISIDE function, but it does not work with dsolve. I got lots of errors. – SuzieQ Apr 13 '16 at 19:09
  • 2
    SuzieQ: `heaviside` is not the only solution suggested @Amro's related answers. Have you tried MuPAD's `piecewise` as I [suggested here](http://math.stackexchange.com/a/868038/80812)? Also, your current code isn't even runnable. `g(x)` depends on itself which makes it recursive. And using a bunch of floating point values in a symbolic expression is likely to make solving symbolically harder. Finally, is there a reason you're using symbolic math rather than solving this numerically with `ode45`? – horchler Apr 13 '16 at 22:12
  • @horchler thanks!I tried to solve the problem using symbolic math according to all the above suggestions, but matlab could not return an explicit or an implicit solution. The reason I chose symbolic math is that after plotting the final function, I want to be able to integrate,find min/max values and other stuff. Do you know if I will be able to perform these things if I solve this numerically with bvp4c ??(since I have boundary conditions). Thanks. – SuzieQ Apr 18 '16 at 16:47

0 Answers0