Question

I try to write a function by parts in GNUplot where f(x) is a constant (floating number) and it just works when the constant is an integer.The error is

'non-integer passed to boolean operator'

This is my code:

R=53.
R0=40.
rho1=339.7
rho2=383.4
rhom=333.4

f1(x)=x<=R0 ? rho1 : rho2 && x>=R ? rhom : rho2
p f1(x)

Could anybody help me with this (most likely) stupid problem?

Thank you

Was it helpful?

Solution

The error is on f1(x) definition. It has boolean result. The function

f1(x)= (x<=R0 ? rho1 : rho2) && (x>=R ? rhom : rho2)

for x=40 returns

f1(x)= (true) && (false) -> false

which is boolean.

If you would like to plot rho1 for x<=R0, rho2 for x in (R0,R) and rhom for x=>R then you have to use:

f1(x)= (x<=R0 ? rho1 : (x>=R ? rhom : rho2) )
p [20:80] f1(x)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top