Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.8K Views
|
8 Replies
|
4 Total Likes
View groups...
Share
Share this post:

[?] Write a constraint on list elements when using Maximize ?

Posted 9 years ago
POSTED BY: Narjes Kandil
8 Replies

Glad to help.

I find the [FormalP] variables hard to read especially when posting to the web-- I suggest using regular variable names unless you need to use them for your notation. Another approach is to use regular variable names like "p" or "pvars" and then replace them with the notation you want for display purposes.

for example:

expression = p[1] + p[2]
expression /. p-> \[FormalP]

In your case the entire problem is in a Module so you can't see the equations anyway so I would recommend using simple variable names.

POSTED BY: Neil Singer
Posted 9 years ago
POSTED BY: Narjes Kandil
POSTED BY: Neil Singer
Posted 9 years ago

Here's my code , I did like you told me

Module[
 {
  \[Alpha] = 100,
  \[Beta] = 10,
  c = 10,
  b = 0.05,
  e = 100,
  k = 500,
  a = 10000,
  t = 0.01 *Range[5],
  m,
  f
  },
 (*m=(a+ \[Alpha] p[[n-1]]- \[Alpha] c - (Length[t]-n) \
a)/(\[Alpha](b+(Length[t]-n+1)t[n]- Sum[t[[i]],{i,n+1, Length[t]}]));*)


 f[x0_, pList_] := (pList[[1]] - 
      c - (b + t[[1]]) x0) (a - \[Alpha] pList[[1]]) +
   Sum[ (pList[[i]] - 
       c - (b + t[[i]]) x0) (a - \[Beta]  pList[[
         i]] + \[Beta]  pList[[i - 1]] - \[Alpha] pList[[1]]), {i, 2, 
     Length[t]}] - k (e - x0)^2;

 Maximize[
  {
   f[\[FormalX], Array[\[FormalP], Length[t]]],
     And @@ Thread[Array[\[FormalP], Length[t]] > 0] && 
    And @@ Table[
      a - \[Beta] (p[i] + p[i - 1]) - \[Alpha] p[1] > 0, {i, 2, 
       Length[t]}] 
   },
  Flatten[{\[FormalX], Array[\[FormalP], Length[t]]}] 
  ]

 ]

and i have this output :

Maximize[{-500 (100 - \[FormalX])^2 + (10000 - 
      100 \[FormalP][1]) (-10 - 
      0.06 \[FormalX] + \[FormalP][1]) + (10000 - 90 \[FormalP][1] - 
      10 \[FormalP][2]) (-10 - 
      0.07 \[FormalX] + \[FormalP][2]) + (10000 - 100 \[FormalP][1] + 
      10 \[FormalP][2] - 10 \[FormalP][3]) (-10 - 
      0.08 \[FormalX] + \[FormalP][3]) + (10000 - 100 \[FormalP][1] + 
      10 \[FormalP][3] - 10 \[FormalP][4]) (-10 - 
      0.09 \[FormalX] + \[FormalP][4]) + (10000 - 100 \[FormalP][1] + 
      10 \[FormalP][4] - 10 \[FormalP][5]) (-10 - 
      0.1 \[FormalX] + \[FormalP][5]), \[FormalP][1] > 
    0 && \[FormalP][2] > 0 && \[FormalP][3] > 0 && \[FormalP][4] > 
    0 && \[FormalP][5] > 0 && 
   10000 - 100 p[1] - 10 (p[1] + p[2]) > 0 && 
   10000 - 100 p[1] - 10 (p[2] + p[3]) > 0 && 
   10000 - 100 p[1] - 10 (p[3] + p[4]) > 0 && 
   10000 - 100 p[1] - 10 (p[4] + p[5]) > 0}, {\[FormalX], \[FormalP][
   1], \[FormalP][2], \[FormalP][3], \[FormalP][4], \[FormalP][5]}]
POSTED BY: Narjes Kandil
Posted 9 years ago

it does not run and returns Maximize [...] numerical expression. Does this mean that I have a syntax error ? I'm actually on the trial version and i'm learning Mathematica.

POSTED BY: Narjes Kandil
POSTED BY: Neil Singer
Posted 9 years ago
POSTED BY: Narjes Kandil
POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard