1

After some simplifications I was eventually get the following piecewise function.

mypdf[x_] =Piecewise[{
    {Indeterminate, x == -1.12568412580949}, 
    {(E^(-0.42044483028504587*x - 1.222667146921728*Sqrt[1.1256841258094925 + 1.*x])*(0.04164934621418419 + 0.04164934621418419*E^(2.445334293843456*Sqrt[1.1256841258094925 + 1.*x])))/Sqrt[1.1256841258094925 + 1.*x],
           1.*Sqrt[1.1256841258094925 + 1.*x] >= 1.2241479465411274}, 
     {(E^(-1.3335678123173245*x - 1.222667146921728*Sqrt[1.1256841258094925 + 1.*x])*(0.04164934621418419*E^(0.9131229820322787*x) + 0.05004800901350002*E^(0.42044483028504587*x + 2.4453342938612392*Sqrt[1.1256841258094925 + 1.*x])))/Sqrt[1.1256841258094925 + 1.*x], 
           1.*Sqrt[1.1256841258094925 + 1.*x] >= 1.2241479465050318},
     {(E^(-0.42044483028504587*x -1.222667146921728*Sqrt[1.1256841258094925 + 1.*x])*(0.05620334996303362 +0.05620334996303362*E^(2.445334293843456*Sqrt[1.1256841258094925 +1.*x])))/Sqrt[1.1256841258094925 + 1.*x],
           1.*Sqrt[1.1256841258094925 + 1.*x] <= 0.9435301862601678},
     {(E^(-1.3335678123173245*x - 1.222667146939511*Sqrt[1.1256841258094925 + 1.*x])*(0.05004800901350002*E^(0.42044483028504587*x) + 0.05620334996303362*E^(0.9131229820322787*x + 2.4453342938612392*Sqrt[1.1256841258094925 + 1.*x])))/Sqrt[1.1256841258094925 + 1.*x],
           1.*Sqrt[1.1256841258094925 + 1.*x] <= 0.9435301862962627},
     {(E^(-0.9131229820322787*x - 1.222667146939511*Sqrt[1.1256841258094925 + 1.*x])*(0.05004800901350002 + 0.05004800901350002*E^(2.445334293879022*Sqrt[1.1256841258094925 + 1.*x])))/Sqrt[1.1256841258094925 + 1.*x], 
           x >= -1.12568412580949}}, 0]

But I dont understand why Mathematica outputs such a strange form?! Because first of all, the function is defined $2$ times in this range $1. Sqrt[1.12568 + 1. x] >= 1.22415$ and two times in this range $1. Sqrt[1.12568 + 1. x] <= 0.94353$.

Even worse the functions for the same range or condition are not the same! However, I am able to plot this function very nicely. Below is a plot of it

enter image description here

My eventual aim is to transfer this function to Matlab. I know how to do it from here but piecewise function is not recognized by Matlab and I want to define it if possible in terms of UnitSteps. I am also able to do it but as I mentioned the piecewise function above is very strange! the conditions are not defined in terms of for example $0.9<x$ but for example $1. Sqrt[1.12568 + 1. x] <= 0.94353$.

Is it possible to obtain a unser friendly non-ugly function so that I can transer it to Matlab? Why is it two times defined in the same range by Mathematica?

Seyhmus Güngören
  • 2,465
  • 1
  • 18
  • 19
  • 2
    The "2 times defined" are actually different: 1.` Sqrt[1.1256841258094925` + 1.` x] >= 1.2241479465411274 and 1.` Sqrt[1.1256841258094925` + 1.` x] >= 1.2241479465050318. It's a small difference, but a difference nonetheless. And the first one does not preclude the second one from being satisfied. Piecewise "falls" through the cases. The first condition that is true determines the value. – Michael E2 Oct 27 '14 at 03:24
  • @MichaelE2 so you are suggesting to take the first condition of both cases. Then I would square both sides of the conditions, simplify and then represent the piecewise function manually in terms of unitsteps. – Seyhmus Güngören Oct 27 '14 at 03:29
  • Is there any way to do convertion from piecewise to unitstep form authomatically? – Seyhmus Güngören Oct 27 '14 at 03:39
  • I'm suggesting that the original computation might not determine the inequalities sufficiently precisely. 2) I don't know of an automatic way to convert to UnitStep. 3) This will simplify the inequalities: MapAt[Reduce, mypdf[x], {1, All, 2}]. 4) This will remove the overlaps: `foo = mypdf[x];
  • foo[[1, All, 2]] = With[{conds = mypdf[x][[1, All, 2]]}, FoldList[{Or[First@#1, #2], Reduce[#2 && ! Last@#1]} &, {False, Reduce@First[conds]}, Rest[conds]][[All, 2]]]; foo`, but I don't think that will be a computational improvement.

    – Michael E2 Oct 27 '14 at 10:31
  • @MichaelE2 this was actually all I needed. Why not posting it as an answer? – Seyhmus Güngören Oct 27 '14 at 21:07