Appending _?NumericQ automatically to every variable of a function in the definition
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I have a list of expressions as follows:
as=Table[a[k],k,1,500]
I would like to append _?NumericQ
to every element of this list and the result should look like this
a[1]_?NumericQ,a[2]_?NumericQ,...,a[500]_?NumericQ
Then I would like to transform this thing to
a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ
For this I need to be able to transform
as=a[1],...,a[500]
to
bs=a1,...,a500
This is needed when one needs to define functions with alot of variables such that hand typing them is not fiesable and symbolic computations are not desired.
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
function-construction argument-patterns
add a comment |Â
up vote
3
down vote
favorite
I have a list of expressions as follows:
as=Table[a[k],k,1,500]
I would like to append _?NumericQ
to every element of this list and the result should look like this
a[1]_?NumericQ,a[2]_?NumericQ,...,a[500]_?NumericQ
Then I would like to transform this thing to
a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ
For this I need to be able to transform
as=a[1],...,a[500]
to
bs=a1,...,a500
This is needed when one needs to define functions with alot of variables such that hand typing them is not fiesable and symbolic computations are not desired.
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
function-construction argument-patterns
What's wrong withTable[a[k]_?NumericQ,k,1,500]
?
– AccidentalFourierTransform
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective functionobj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?
– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
2
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a list of expressions as follows:
as=Table[a[k],k,1,500]
I would like to append _?NumericQ
to every element of this list and the result should look like this
a[1]_?NumericQ,a[2]_?NumericQ,...,a[500]_?NumericQ
Then I would like to transform this thing to
a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ
For this I need to be able to transform
as=a[1],...,a[500]
to
bs=a1,...,a500
This is needed when one needs to define functions with alot of variables such that hand typing them is not fiesable and symbolic computations are not desired.
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
function-construction argument-patterns
I have a list of expressions as follows:
as=Table[a[k],k,1,500]
I would like to append _?NumericQ
to every element of this list and the result should look like this
a[1]_?NumericQ,a[2]_?NumericQ,...,a[500]_?NumericQ
Then I would like to transform this thing to
a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ
For this I need to be able to transform
as=a[1],...,a[500]
to
bs=a1,...,a500
This is needed when one needs to define functions with alot of variables such that hand typing them is not fiesable and symbolic computations are not desired.
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
function-construction argument-patterns
function-construction argument-patterns
edited 2 hours ago
Michael E2
142k11192458
142k11192458
asked 2 hours ago
Seyhmus Güngören
1,05811017
1,05811017
What's wrong withTable[a[k]_?NumericQ,k,1,500]
?
– AccidentalFourierTransform
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective functionobj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?
– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
2
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago
add a comment |Â
What's wrong withTable[a[k]_?NumericQ,k,1,500]
?
– AccidentalFourierTransform
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective functionobj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?
– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
2
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago
What's wrong with
Table[a[k]_?NumericQ,k,1,500]
?– AccidentalFourierTransform
2 hours ago
What's wrong with
Table[a[k]_?NumericQ,k,1,500]
?– AccidentalFourierTransform
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective function
obj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?– Seyhmus Güngören
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective function
obj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
2
2
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
4
down vote
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ
for each variable, you can use PatternSequence
:
f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := a1, a1+a4, a2+a3, a5
Check:
f[1,2,3,4,5]
f[1,2,a,4,5]
1, 5, 5, 5
f[1, 2, a, 4, 5]
add a comment |Â
up vote
2
down vote
What about this?
With[
lhs = ReplacePart[
Table[
PatternTest[
Pattern[Evaluate[Symbol["a" <> IntegerString[k]]], Blank],
NumericQ
],
k, 1, 500
],
0 -> obj
],
rhs = 1
,
SetDelayed[lhs, rhs]
]
The list of variables can be obtained with
Table[Symbol["a" <> IntegerString[k]], k, 1, 500]
But on the long run, a better strategy might be to define your function like so:
obj[a_?(VectorQ[#,NumericQ]&)] := ...
and to refer to the entries of a
with Indexed[a,i]
on the right hand side. (And yes, functions like FindMinimum
and FindRoot
can be convinced to work such functions.)
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the bracketsobj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.
– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has:
additionally.
– Seyhmus Güngören
2 hours ago
WithToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous:
, please see my edit.
– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired functionobj
. Check out??obj
.lhs
is the pattern for which the rule is defined (the "function"),rhs
is the expression that is supposed to be evaluated when the function is called. Here, I putrhs = 1
.
– Henrik Schumacher
2 hours ago
add a comment |Â
up vote
2
down vote
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
In this case I think it would be much simpler to use something like
obj[vars__?NumericQ /; Length[vars] === 5] := Module[
a1, a2, a3, a4, a5,
a1, a2, a3, a4, a5 = vars;
(* do something useful here, like *)
Total @ a1, a2, a3, a4, a5
]
Now obj
behave exactly as you want, but you don't have to do any voodoo with creating your definition.
In[11]:= obj[1, 2, 3, 4, 5]
Out[11]= 15
In[12]:= obj[1, 2, 3, a + 4, 5]
Out[12]= obj[1, 2, 3, 4 + a, 5]
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ
for each variable, you can use PatternSequence
:
f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := a1, a1+a4, a2+a3, a5
Check:
f[1,2,3,4,5]
f[1,2,a,4,5]
1, 5, 5, 5
f[1, 2, a, 4, 5]
add a comment |Â
up vote
4
down vote
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ
for each variable, you can use PatternSequence
:
f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := a1, a1+a4, a2+a3, a5
Check:
f[1,2,3,4,5]
f[1,2,a,4,5]
1, 5, 5, 5
f[1, 2, a, 4, 5]
add a comment |Â
up vote
4
down vote
up vote
4
down vote
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ
for each variable, you can use PatternSequence
:
f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := a1, a1+a4, a2+a3, a5
Check:
f[1,2,3,4,5]
f[1,2,a,4,5]
1, 5, 5, 5
f[1, 2, a, 4, 5]
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ
for each variable, you can use PatternSequence
:
f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := a1, a1+a4, a2+a3, a5
Check:
f[1,2,3,4,5]
f[1,2,a,4,5]
1, 5, 5, 5
f[1, 2, a, 4, 5]
answered 1 hour ago


Carl Woll
61.7k280157
61.7k280157
add a comment |Â
add a comment |Â
up vote
2
down vote
What about this?
With[
lhs = ReplacePart[
Table[
PatternTest[
Pattern[Evaluate[Symbol["a" <> IntegerString[k]]], Blank],
NumericQ
],
k, 1, 500
],
0 -> obj
],
rhs = 1
,
SetDelayed[lhs, rhs]
]
The list of variables can be obtained with
Table[Symbol["a" <> IntegerString[k]], k, 1, 500]
But on the long run, a better strategy might be to define your function like so:
obj[a_?(VectorQ[#,NumericQ]&)] := ...
and to refer to the entries of a
with Indexed[a,i]
on the right hand side. (And yes, functions like FindMinimum
and FindRoot
can be convinced to work such functions.)
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the bracketsobj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.
– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has:
additionally.
– Seyhmus Güngören
2 hours ago
WithToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous:
, please see my edit.
– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired functionobj
. Check out??obj
.lhs
is the pattern for which the rule is defined (the "function"),rhs
is the expression that is supposed to be evaluated when the function is called. Here, I putrhs = 1
.
– Henrik Schumacher
2 hours ago
add a comment |Â
up vote
2
down vote
What about this?
With[
lhs = ReplacePart[
Table[
PatternTest[
Pattern[Evaluate[Symbol["a" <> IntegerString[k]]], Blank],
NumericQ
],
k, 1, 500
],
0 -> obj
],
rhs = 1
,
SetDelayed[lhs, rhs]
]
The list of variables can be obtained with
Table[Symbol["a" <> IntegerString[k]], k, 1, 500]
But on the long run, a better strategy might be to define your function like so:
obj[a_?(VectorQ[#,NumericQ]&)] := ...
and to refer to the entries of a
with Indexed[a,i]
on the right hand side. (And yes, functions like FindMinimum
and FindRoot
can be convinced to work such functions.)
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the bracketsobj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.
– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has:
additionally.
– Seyhmus Güngören
2 hours ago
WithToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous:
, please see my edit.
– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired functionobj
. Check out??obj
.lhs
is the pattern for which the rule is defined (the "function"),rhs
is the expression that is supposed to be evaluated when the function is called. Here, I putrhs = 1
.
– Henrik Schumacher
2 hours ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
What about this?
With[
lhs = ReplacePart[
Table[
PatternTest[
Pattern[Evaluate[Symbol["a" <> IntegerString[k]]], Blank],
NumericQ
],
k, 1, 500
],
0 -> obj
],
rhs = 1
,
SetDelayed[lhs, rhs]
]
The list of variables can be obtained with
Table[Symbol["a" <> IntegerString[k]], k, 1, 500]
But on the long run, a better strategy might be to define your function like so:
obj[a_?(VectorQ[#,NumericQ]&)] := ...
and to refer to the entries of a
with Indexed[a,i]
on the right hand side. (And yes, functions like FindMinimum
and FindRoot
can be convinced to work such functions.)
What about this?
With[
lhs = ReplacePart[
Table[
PatternTest[
Pattern[Evaluate[Symbol["a" <> IntegerString[k]]], Blank],
NumericQ
],
k, 1, 500
],
0 -> obj
],
rhs = 1
,
SetDelayed[lhs, rhs]
]
The list of variables can be obtained with
Table[Symbol["a" <> IntegerString[k]], k, 1, 500]
But on the long run, a better strategy might be to define your function like so:
obj[a_?(VectorQ[#,NumericQ]&)] := ...
and to refer to the entries of a
with Indexed[a,i]
on the right hand side. (And yes, functions like FindMinimum
and FindRoot
can be convinced to work such functions.)
edited 2 hours ago
answered 2 hours ago


Henrik Schumacher
42.6k261125
42.6k261125
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the bracketsobj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.
– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has:
additionally.
– Seyhmus Güngören
2 hours ago
WithToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous:
, please see my edit.
– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired functionobj
. Check out??obj
.lhs
is the pattern for which the rule is defined (the "function"),rhs
is the expression that is supposed to be evaluated when the function is called. Here, I putrhs = 1
.
– Henrik Schumacher
2 hours ago
add a comment |Â
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the bracketsobj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.
– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has:
additionally.
– Seyhmus Güngören
2 hours ago
WithToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous:
, please see my edit.
– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired functionobj
. Check out??obj
.lhs
is the pattern for which the rule is defined (the "function"),rhs
is the expression that is supposed to be evaluated when the function is called. Here, I putrhs = 1
.
– Henrik Schumacher
2 hours ago
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the brackets
obj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.– Seyhmus Güngören
2 hours ago
that seems great. I need to know two more things. 1. I need to get rid of the brackets of a list, because with the brackets
obj[]:=
definition does not work. 2. I also need the list a1,a2,...,a500.– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has
:
additionally.– Seyhmus Güngören
2 hours ago
why is toexpression dangerous? the second one has
:
additionally.– Seyhmus Güngören
2 hours ago
With
ToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous :
, please see my edit.– Henrik Schumacher
2 hours ago
With
ToExpression
there is the possibility that some string with harmfull code can be injected. Notice that Mathematica has write access to your local files. For superfluous :
, please see my edit.– Henrik Schumacher
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
what is this code doing? It does not give any output. What is lhs and rhs btw? how to delete the brackets $$ and $$?
– Seyhmus Güngören
2 hours ago
This code defines your desired function
obj
. Check out ??obj
. lhs
is the pattern for which the rule is defined (the "function"), rhs
is the expression that is supposed to be evaluated when the function is called. Here, I put rhs = 1
.– Henrik Schumacher
2 hours ago
This code defines your desired function
obj
. Check out ??obj
. lhs
is the pattern for which the rule is defined (the "function"), rhs
is the expression that is supposed to be evaluated when the function is called. Here, I put rhs = 1
.– Henrik Schumacher
2 hours ago
add a comment |Â
up vote
2
down vote
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
In this case I think it would be much simpler to use something like
obj[vars__?NumericQ /; Length[vars] === 5] := Module[
a1, a2, a3, a4, a5,
a1, a2, a3, a4, a5 = vars;
(* do something useful here, like *)
Total @ a1, a2, a3, a4, a5
]
Now obj
behave exactly as you want, but you don't have to do any voodoo with creating your definition.
In[11]:= obj[1, 2, 3, 4, 5]
Out[11]= 15
In[12]:= obj[1, 2, 3, a + 4, 5]
Out[12]= obj[1, 2, 3, 4 + a, 5]
add a comment |Â
up vote
2
down vote
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
In this case I think it would be much simpler to use something like
obj[vars__?NumericQ /; Length[vars] === 5] := Module[
a1, a2, a3, a4, a5,
a1, a2, a3, a4, a5 = vars;
(* do something useful here, like *)
Total @ a1, a2, a3, a4, a5
]
Now obj
behave exactly as you want, but you don't have to do any voodoo with creating your definition.
In[11]:= obj[1, 2, 3, 4, 5]
Out[11]= 15
In[12]:= obj[1, 2, 3, a + 4, 5]
Out[12]= obj[1, 2, 3, 4 + a, 5]
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
In this case I think it would be much simpler to use something like
obj[vars__?NumericQ /; Length[vars] === 5] := Module[
a1, a2, a3, a4, a5,
a1, a2, a3, a4, a5 = vars;
(* do something useful here, like *)
Total @ a1, a2, a3, a4, a5
]
Now obj
behave exactly as you want, but you don't have to do any voodoo with creating your definition.
In[11]:= obj[1, 2, 3, 4, 5]
Out[11]= 15
In[12]:= obj[1, 2, 3, a + 4, 5]
Out[12]= obj[1, 2, 3, 4 + a, 5]
Actually I only want to define a function with many variables as
obj[a1_?NumericQ,a2_?NumericQ,...,a500_?NumericQ]
In this case I think it would be much simpler to use something like
obj[vars__?NumericQ /; Length[vars] === 5] := Module[
a1, a2, a3, a4, a5,
a1, a2, a3, a4, a5 = vars;
(* do something useful here, like *)
Total @ a1, a2, a3, a4, a5
]
Now obj
behave exactly as you want, but you don't have to do any voodoo with creating your definition.
In[11]:= obj[1, 2, 3, 4, 5]
Out[11]= 15
In[12]:= obj[1, 2, 3, a + 4, 5]
Out[12]= obj[1, 2, 3, 4 + a, 5]
answered 2 hours ago


Jason B.
46.6k383179
46.6k383179
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184399%2fappending-numericq-automatically-to-every-variable-of-a-function-in-the-defini%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What's wrong with
Table[a[k]_?NumericQ,k,1,500]
?– AccidentalFourierTransform
2 hours ago
@AccidentalFourierTransform maybe nothing but it doesnt solve my problem. Normally we use _?NumericQ to speed up the process just with numerical computations. If I have $500$ variables, say $a1,...,a500$, I have an objective function
obj[a1_?NumericQ,a2_?NumericQ........]
I want to defined this without writing $500$ terms over there... Is it possible to let the mathematica do this for me?– Seyhmus Güngören
2 hours ago
I edited the question.
– Seyhmus Güngören
2 hours ago
2
Possible duplicate: mathematica.stackexchange.com/questions/68866/…
– Michael E2
2 hours ago
Definitely check out the link in @MichaelE2's comment -- Szabolcs's answer should be a much cleaner solution.
– Chris K
1 hour ago