You can define a piecewise function as a symbolic function. For example...
M_xy(t) = piecewise(t < 0, 0, t > 0, t);
M_xz(t) = piecewise(t < 0, 0, t > 0, 2*t);
r = sqrt(M_xy(3.75)^2 + M_xz(3.75)^2)
r =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1667536/image.png)
That is, you can now evaluate these things directly as functions of t. If you wanted to define r itself as a function of t, you could have done this
r(t) = sqrt(M_xy(t)^2 + M_xz(t)^2);
And now r is itself a function you can evaluate.
r(3.75)
ans =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1667541/image.png)
(Which is the same number as before. Strangely, it did not decide to simplify that result.) Anyway, you can even use r in a vectorized form.
r(1:.5:4)
ans =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1667546/image.png)
And of course, we can turn these into doubles, or you can use vpa.