1791 Views 16 Replies Latest reply: Mar 12, 2012 11:36 AM by ptc-4310378
165 posts since
Nov 5, 2011
Currently Being Moderated

## Using Maximize Function within a program?

In the attached file, the Maximise Function is used against an  5 x 1 Array and is manully repeated 5 times, using a different guess for each case.

Trying to streamline the process, tried to do the five steps with a program but the program fails.

It looks like the maximise function inside the Program is not accepting the Guess value assigned within the program and is picking up the a Global Value for the guess, outside of the program, different from the assign value inside the program.

What would be the proper way to use Maximize within a Program>

Thank you

Laurent

Attachments:
• 10,405 posts since
May 11, 2010
Currently Being Moderated
Mar 9, 2012 4:26 PM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

You can turn a maximize solve block into a function, and can therefore use it in a program (you cannot embed it in a program, but you can use it in a program). I'm just really busy right now and I'm out at a conference next week. I'll see if I can find time to look at your worksheet tomorrow, but I'm not making any promises.

• 1,278 posts since
Jun 8, 2010
Currently Being Moderated
Mar 10, 2012 1:28 AM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

No need to keep redefining the function.  See bottom of the attached file.

Alan

Attachments:
• 1,278 posts since
Jun 8, 2010
Currently Being Moderated
Mar 10, 2012 3:23 AM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

Laurent Muller wrote:

May I ask the reason for assigning step 1 outside of the loop and running the loop from 2 to 5 instead of doing it all in a 1 to 5 loop?

Stupidity on my part!  It was a left-over from my first attempt, where I tried to use the solution at step i-1 as the guess for step i.  That was before I noticed exactly how you had set your initial guesses.  You can safely delete step 1 and run the loop from 1 to 5.

In fact, you don't even need the programming structure. Just copy the line within the loop and paste it outside the programming structure and it runs ok (the results are contained in SSSwf not PSSwf of course).

Alan

• 1,278 posts since
Jun 8, 2010
Currently Being Moderated
Mar 11, 2012 5:48 AM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

Laurent Muller wrote:

Absolutely no clue about may be happening there.

Possibly because you used a function when a simple vector would do.  I've also simplified your Given ... Find solve block significantly - see attached.

Alan

Attachments:
• 1,278 posts since
Jun 8, 2010
Currently Being Moderated
Mar 12, 2012 2:19 AM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

Laurent Muller wrote:

2001 doesn't want to have anything to do with the compact structure for the Solve...Given you came up with in 15! To begin with, 2001 wants to have the Guess as an Array the same size as the Solution Array....

As the calcs are also faster in 15, I'll have to plug away in 15 for this one.

I would have a question about the Guess for the Solve: How did you come up with the initial guess value of 0?

I have never seen anything like that with a Solver before: 0 is for sure not a possible solution, but the Solver fails for any other value of the guess. Strange....and scary!  But seing how methodic you are, there is most likely some logic behind this choice?

Thank you.

Can't help with the 2001 version.  I haven't had that version available to play with for years now!

There was no great logic behind the choice of 0 as an initial guess.  It's just a number of the same order as the outputs that were produced (where they were produced) by your initial guess of 0.5.  As it happened it worked - it might not have!

I think the strange behaviour that you observed (I observed some myself with your original file) might be related to the fact that you chose to use the word "time" as a range variable.  Unfortunately, "time" is a built-in function that doesn't seem to like being re-defined.  The strange behaviour disappeared when I used a different variable name.

Alan

• 1,278 posts since
Jun 8, 2010
Currently Being Moderated
Mar 12, 2012 4:26 AM (in response to ptc-4310378)
Re: Using Maximize Function within a program?

Incidentally, you might want to check your values of krw.  Since some values of Swd are negative the corrsponding values of krw are complex (I assume these are unphysical) - That's why not all the values have plotted on your graphs.

Alan

#### More Like This

• Retrieving data ...

#### Legend

• Correct Answers - 3 points