Mathematica Mathematica maximize element extraction from list

AI Thread Summary
To maximize the extracted value from a list in Mathematica while adhering to constraints on the index, the user seeks a solution to avoid errors when using the Extract function. The example provided shows an attempt to extract the maximum value from the list S = {4, 2, 3, 5} with constraints on the index x. The error arises because the index x must be an integer or a list of integers. A suggested alternative is using the Max function with the Take function to specify the range of indices, which successfully returns the maximum value of 4. The discussion emphasizes the need for proper index specification in extraction functions.
parzio
Messages
4
Reaction score
0
Hi guys,

I think this is a simple question for mathematica experts.
How can I maximize the extracted value from a list given a index that has to respect some constrains?

For example:

S = {4,2,3,5}

Maximize[{Extract[S,x], x<= 3, x>=1},{x}]

I would like 4 is returned instead of this error:
Extract::psl: "Position specification x in Extract[{4,2,3,5},x] is not an integer or a list of integers."

Does someone know like solve this?

Thanks a lot.
 
Physics news on Phys.org
In[1]:= S={4,2,3,5};Max[Take[S,{1,3}]]

Out[2]= 4
 

Similar threads

Replies
4
Views
1K
Replies
3
Views
4K
Replies
5
Views
2K
Replies
13
Views
2K
Replies
6
Views
4K
Replies
8
Views
5K
Replies
22
Views
3K
Replies
1
Views
2K
Back
Top