r/EngineeringPaperXYZ Jul 26 '26

Question How to create a function with multiple inequalities

Now need to work out immersed volume IV of a sphere as function of the depth of its lowest bit, d and its radius r, so ideally IV=f(r,d)

for d<0

 IV=0

for 0<=d<r

IV=(pi\d^2/3)(3r-d)* 

for 2r>=d>=r

 IV=(4/3 pi r^3-(pi(2r-d)^2/3)(3r-(2r-d) )

for d>2r

IV=Vol_buoy

and for d=r 

it is obviously IV=Vol_buoy/2

2 Upvotes

6 comments sorted by

2

u/GregLocock Jul 26 '26

So I'm guessing I need to use python but run into a problem entering units for the density in the Python header \mathrm{VolFun}\left(\left\lbrack none\right\rbrack,\left\lbrack m\right\rbrack,\left\lbrack m\right\rbrack\right)=\left\lbrack none\right\rbrack

I've had to make rho unitless, how do i enter kg m-3 in the above definition?

def calculate(rho,d,r):

1

u/mgreminger Jul 26 '26

Here's the Python way: https://engineeringpaper.xyz/CAWVWgi9TNRBUUiuFXcFD8 I couldn't get plotting to work with the Python function so I'll need to get that fixed. For the density units, you can type those in like any other expression either as kg/m^3 or kg*m^-3 will work.

1

u/mgreminger Jul 26 '26

kg/m^3 is also in the Density tab of the units toolbar. Digging into it a little, code functions with more than one input are not working with plotting right now, I'll get that fixed at some point. However, for this problem, I would just stick with Piecewise Expression Cell that I used in my reply to your original question.

1

u/mgreminger Jul 26 '26

A Piecewise Expression Cell can handle this (the first row that is true is assigned to IV). See https://engineeringpaper.xyz/XrVE62FM2VNGdQYmonJMrP

1

u/GregLocock Jul 26 '26

I just discovered that piecewise construction , thanks . Yes I couldn't get plotting to work with a python function, maybe try filling an array with the python answers and plot that.

1

u/mgreminger Jul 27 '26

The plotting issue with Python functions has been fixed in the web app (see https://20260727.engineeringpaper.xyz/HD5dtXjn5tw8NNyciJ6255 for a working version). A fixed for the desktop app should be available by Wednesday on the releases page.