Qucs / qucs

Qucs Project official mirror
http://qucs.sourceforge.net/
GNU General Public License v2.0
1.16k stars 213 forks source link

How to write piecewise function in equation-model? #843

Closed Liampor closed 6 years ago

Liampor commented 6 years ago

Hello everyone,

I would like to ask how to write piecewise funktion like

x = 1 for 1<= x < 2 x = x for 2 <= x

Thank you all

in3otd commented 6 years ago

hello, if you are referring to the EDD component, take a look at the Curtice level 1 MESFET model example on the Qucs website. The curtice_1.sch schematic there has an EDD component that implements a piecewise function using the ternary if operator ( condition ? a : b ).

Liampor commented 6 years ago

@in3otd thanks for your nice answer

Liampor commented 6 years ago

@in3otd

to get function

res = 19 for 1e6 <=frequency < 10e6

I wrote

res = frequency>=1e6 && frequency<10e6 ? 11 : 0

but always got

checker error, no appropriate function for `((frequency>=1e+006)&&(frequency<1e+007))' found
checker error, no appropriate function for `(((frequency>=1e+006)&&(frequency<1e+007))?11:0)' found
checker error, type of equation `res' undefined

What's the Problem ?

in3otd commented 6 years ago

frequency is a vector so the result of the comparisons is a vector too: the two alternatives then need to be vectors too. There is no "broadcasting" of the arguments. But it's better to explain what you are trying to achieve here, I suspect this may not be the right way.

Liampor commented 6 years ago

@in3otd thanks for your anser, I just want to add a reference curve to figure. The referene curve is a piecewise function, for exampe

res = 19 for 1e6 <=frequency < 10e6 res = 35 for 10e6 =< frequency

Could you tell me which is the right way for this?

Thanks

in3otd commented 6 years ago

um, it should be easier but the only way I can think of is something like this export It's a pity that the and (&&) operator does not work on vectors.

For more complex reference lines you may also try writing directly the values to a .dat dataset file and plot it together with your data.

Liampor commented 6 years ago

@in3otd very nice,it is very helpful