0

I have a List j={j[1],j[3],j[6]}. But this list is in fact a variable of my code, so i could have j={j[6],j[10]} either.

I need to define a function like this :

F[j[[1]]_,j[[2]]_,...,j[[n]]_]:=AFunction

So I wanted to do the following:

seqList=Sequence @@ j
F[seqList]:=AFunction

But the problem with that is seqList will not have the "_" after the variable. I would have a sequence that will look like j[[1]],j[[2]],... and NOT j[[1]]_, j[[2]]_

So how to define a sequence of parameters with the "_" after.


What is my actual goal :

I need to automatize a polynomial identification at the maximum.

I have a function that creates a polynomial with variable coefficient. This is :

CreerPoly[{j}, {degrees}]

For example if I want to create a polynome depending on x and y with degree 2 in aa and 1 in bb I will call CreerPoly[{aa,bb}, {2,1}]

And it will return me :

A[0, 0] + bb A[0, 1] + aa A[1, 0] + aa bb A[1, 1] + aa^2 A[2, 0] + 
 aa^2 bb A[2, 1]

I have a script that determines on how many variables my polynome will depends and at which degree.

And I need from this information to create the associated polynome.

But as I need to solve equations, I want that this polynome is a function of the variable I have found because I need to change the variables to solve the equations. For example if it depends on x,y,z I want to have a function : myFinalPolynome[x,y,z]. And of course as I said I don't know at the beginning how many variables I will have in my polynome.

StarBucK
  • 2,164
  • 1
  • 10
  • 33
  • 2
    Can you elaborate what your actual goal is? This looks suspicious like a XY problem and looks like a bad idea. – Sascha Jun 20 '17 at 10:09
  • I updated my question ! – StarBucK Jun 20 '17 at 10:18
  • https://mathematica.stackexchange.com/questions/6588/can-a-function-be-made-to-accept-a-variable-amount-of-inputs + https://mathematica.stackexchange.com/questions/10833/how-do-i-convert-an-argument-list-to-a-list-of-arguments? – Kuba Jun 20 '17 at 10:24
  • 1
    I see many problems with your syntax. If you have j={j[1],j[3],j[6]}, this definition is recursive (you have j on the left and right sides of the assignment). Next, you have patterns named as list elements. j[[n]]_ is not a valid pattern as j[[n]] cannot be used as a name for a pattern. What exactly did you want to achieve with this? I think, you're looking for BlankSequence and BlankNullSequence which allow for variable number of arguments, but it's not clear, why you don't want to have the function take a (variable-length) list as its single argument. – LLlAMnYP Jun 20 '17 at 10:34
  • For j={j[1],j[3],j[6]} you are right, I wrote a little too fast my message. For j[[n]]_ I didn't know we could'nt use it as a Pattern. I added a part to my message to explain what I wanted to do. – StarBucK Jun 20 '17 at 10:36
  • Don't forget to ping, as in @LLlAMnYP otherwise I don't see that you've replied. The first part of your question is really confusing, but I think I'm getting the gist of it finally. As I have asked already, what's wrong with defining your function for a general unknown-length sequence of variables? E.g. f[x__] := Times[x]; f[2,3]->6, f[1]->1, f[4,3,5]->60 or for a list, like f[x_List] := Sum[2i, {i, x}]; f[{1,4,5}]->10 – LLlAMnYP Jun 20 '17 at 10:45
  • @LLlAMnYP Ok I will think to ping now :). Yes I will try to do it, I am thinking about my problem with this trick I think it can help me ! Thanks – StarBucK Jun 20 '17 at 10:47
  • Of course, the last two symbols of my previous comment should read 20. facepalm – LLlAMnYP Jun 20 '17 at 10:53

0 Answers0