Hello community.
I'm having trouble learning how to use these commands (Options, OptionsPattern and OptionValue) by reading and trying through the documentation.
The following function (just a simple example) I can elaborate with optional arguments in this way below:
f1[a_] := f1[a, "ini2", 2, 10];
f1[a_, b_] := f1[a, b, 2, 10];
f1[a_, b_, c_] := f1[a, b, c, 10];
f1[a_, b_, c_, d_] :=
Module[{esca, num, tik,
pattern = <|"pat1" -> {0, 1, 1, 1, 1}, "pat2" -> {0, 2, 2, 2, 2},
"pat3" -> {0, 3, 3, 3, 3}|>}, num = pattern@a;
esca = Flatten@
Map[Map[(b /. {"ini1" -> -10, "ini2" -> -5, "ini3" -> 0,
"ini4" -> 5}) + # &, Accumulate@num] + # &, {0, 10,
20}[[;; c]]]; tik = esca + d]
For example:
f1["pat1", "ini3", 3]
f1["pat1"]
This way above, the function works, but is built using optional arguments. I need it to be in another way, with Options command...
I have to do in a way that the arguments are function Options and not as optional arguments. To do this, the arguments ( "b ", "c " and "d _" ) of the function should be called "option1", “option2" and "option3". The default values for the function should be: "option1"->"ini2", "option2"->2 and "option3"->10.
Examples of Input that I need the function to work:
f1["pat1"]
f1["pat1", "option1" -> "ini3", "option3" -> 15]
f1["pat1", "option2" -> 1]
f1["pat1", "option3" -> 5]
f1["pat1", "option2" -> 3, "option3" -> 20]
f1["pat1", "option1" -> "ini1", "option2" -> 1, "option3" -> 15]
Giving the following results from the above example:
Anyone in the community who knows how to use Options, OptionsPattern, and OptionValue can help me, please??
I tried several times but it has been very difficult for me to understand...for now.
Thank you very much in advance.