add tag
4 years ago JeT

I have a set of of functions I keep re-using (as in this question).

My question

How can I efficiently plot a linear combination of these functions and easily load different scenarios based on different sets of parameters?

My target

Easily plot scenarios based on initial values

I feel limited in my analysis to defined sets of variables The heavy/not elegant code makes me think I am dragging a bad habit (I’d like to correct)

I clumsily use (LinearCombination, LC) LC(\a,\b,\c,\d,\e,\f)=\a*\d+\b*\e+\c*\f ;

I need your thoughts to update all this in a civilized way 😃

ImproveFunctionSetOfVariables.png

Explanations in the MWE below

What I do so far

In a future question, I’ll ask how to load a different format (surf, colormap) along the scenario I load. To get easily the kind of output (the real functions I use in my flow)

ExempleDeMultiImages2.png

Top Answer
4 years ago user 3.14159

This is something rather simple-minded and potentially dangerous, at least if you use it in ways this was not made for. First of all, you can define your set of parameters simply with a style, e.g.

This means that the functions W1 and so on are not defined before you (locally) use the style. However, you also want to redefine the functions. pgf “protects” the functions from being simply overwritten, for good reasons. However, this also means that you cannot just redefine W1. This is usually not a problem because you are supposed to use such functions locally just once, and then there is no need to redefine them. However, in the case at hand in which you want to make small modifications to a large family of parameters. Therefore I added a key force declare function that overwrites functions without complaining. PLEASE USE WITH CARE. Using a variant of this style, redefine, you can modify parameters of your set.

Screen Shot 2021-01-23 at 10.57.53 AM.png

P.S. pgf keys are another option. However, they cannot simply be used in the formulae in the same way as W1, say, gets used above. Therefore I decided to play, for the moment, with fire and use the redefining function route.

4 years
JeT — Wednesday, 10th Nov 2021 11:28

I finally integrated fully your great solution ! Miss reading you here.

10 months
JeT replying to user 3.14159 — Sunday, 24th Jan 2021 00:27

Merci ! I see better the syntax I can play with now. Another long time pb solved 😃

16 minutes
user 3.14159 replying to JeT — Sunday, 24th Jan 2021 00:11

You could perhaps do the following. (It does not do what you are asking for, which is to copy functions, something that is possible but hacky, yet might produce the right results.)

an hour
JeT — Saturday, 23rd Jan 2021 22:48

I could use

\myLC[JeT-set 1]{d1}{d2}{d1} but it feels I lose the initial idea.

an hour
JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 21:31

whereas when I use #1(x,y,K1,R1,Vol1) it works.

JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 21:29

I looked behind my shoulder for 1 second cause that’s exactly what I did.

user 3.14159 replying to JeT — Saturday, 23rd Jan 2021 21:28

I do not know how you defined Option1 etc. If you literally did

then this does not work for several reasons. First of all, the commas need to become ;. More importantly, you are using Option1(x,y,K1,R1,Vol1) to be a function of five variables, but seem to define it as function of 0 variables.

JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 21:19

I think you’re addressing my point before I had time to formulate it !

works well. But i’ll often need to have different functions on each leg. Adding Option1 = d1, Option2=d2, Option3=d2in the style

leads to an error. Must be a question of expansion.

user 3.14159 replying to JeT — Saturday, 23rd Jan 2021 21:14

Yes, but the ; is also important in declare function. One thing I am wondering is if the function are called d1, d2 and so on because they are entries of an array. If so, one may be able to change the strategy.

14 minutes
JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 21:00

OK I’ll avoid Write18 as well !
Everything is smooth and easy. The “;” in redefineis important.
I have many functions named as variant d1 or d2, Nd1 or Nd2. I am working on how to use them as variables to call. Little trouble so far . If anything I’ll write in a bit.

26 minutes
user 3.14159 replying to JeT — Saturday, 23rd Jan 2021 20:35

Glad to hear! Note, however, that you should use it with care. If you ever redefine the sin function, say, by accident you will be in great trouble. (In principle pgf offers the same Pandora box with the starred version, \pgfmathdeclarefunction*, but less users use these constructions.)

16 minutes
JeT — Saturday, 23rd Jan 2021 20:18

@marmot, re: your answer, Your redefine key is great ! It simplifies everything. It fits perfectly into my flow !

30 minutes
JeT — Saturday, 23rd Jan 2021 19:48

@marmot, re: your answer, merci Marmot. I am testing your code. It feels like I’ve just cleaned my room heheh. So much clearer.

an hour
JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 18:24

JeT-Set was a good one 😉

JeT replying to user 3.14159 — Saturday, 23rd Jan 2021 18:23

Bonsoir Marmot ! I did NOT know how to declare function in a style. Point checked merci!
I am eager to see your alternative with keys. I just have the feeling it will (as usual) open new horizons. A kind of grown up solution 😃

user 3.14159 — Saturday, 23rd Jan 2021 18:13

@JeT, re: your question, my naive first reaction would have been to propose something along the lines of

but the problem is that it is not too easy to redeclare functions in an elegant way. That is, if you use the parameter set JeT-set 1 , e.g. WOne is carved in stone. An alternative would be to use just pgf keys. Would this be acceptable? (BTW, you do not need things like WOne, you can declare a function/define a key W1, and so on.)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.