Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Optimization problem using minimize function

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-05-2019
02:56 AM

02-05-2019
02:56 AM

Hello everyone!

This is my first post, I'm glad to be here. Let's cut to the chase.

I have created an objective function which has 5 variables. I gave 5 constraints. Probably a typical problem. But when i try to optimize it with the minimize function mathcad spent all night calculating it and it did not come up with anything. I am new to this, so probably missing the point I will be thankful for any piece of advice.

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
02:07 PM

02-06-2019
02:07 PM

OK, as promised here is my speeded up version.

Hope the my first interpretation of the function Y is the one you need - otherwise we would have to invest some more work to make the solve block respect ALL constraints (if possible at all).

I also include a pdf-print of the sheet.

As you see your original Y-function evaluates in about 12 seconds. The 51 sec of what I wrote earlier came about the fact that my machine was busy with some video recoding which eat up nearly all my CPU power ;-)

So your reduction from 583 points to somewhat over 400 seems not to be necessary at all.

Note that because of the various use of the time() function the sheet will recalculate every time before printing or saving which is annoying. You might want to get rid of tall the unnecessary regions as soon as possible.

22 REPLIES 22

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
03:14 AM

02-06-2019
03:14 AM

Re: Optimization problem using minimize function

Attach please Mathcad-sheet!

Ans second!

Call please your objective function OF after the giving guess values of aa, ab etc!

Use please the Minimize function without constrains and than in put constrains step-by-step!

Good luck!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
05:36 AM

02-06-2019
05:36 AM

Re: Optimization problem using minimize function

Thanks for the reply! I have enclosed the mathcad sheet with excel files, since it reads directly from them. I switched OF function with exact values as you said, but still it doesn't wish to calculate

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
07:00 AM

02-06-2019
07:00 AM

Re: Optimization problem using minimize function

Have you ever tried to call your function OF just ONE TIME?

I did, using your initial values, and after e few minutes it was still calculating and I cancelled the operation.

When trying to minimize, Mathcads algorithm would change your five arguments very often ever so slightly and will then call OF every time. If even one single call of OF takes that long, you can't expect the solve block to finish within a reasonable time.

The first thing to do is to look closer at the objective function if you can find a way to avoid that many nested loops which cost that many time in calculation.

Debugging of your sheet (if someone would be willing to take the time) is made more difficult and hindered by the fact, that the definition of some vital variables (Vol11, T0,..) is not visible as its hidden in a locked area.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
07:08 AM

02-06-2019
07:08 AM

Re: Optimization problem using minimize function

Just one additional observation:

You used the same variable name i for a loop and a sum within this loop.

I guess thats not an error and that Mathcad can handle this correct but its sure bad style and irritating. You may want to change the name of one of those variables as seen in the attached picture.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
07:21 AM

02-06-2019
07:21 AM

Re: Optimization problem using minimize function

Here is a first suggestion for an optimization of your sheet.

The way you had defined OF, the function Y is called for every summand of your sum, meaning it is called 583 times!

One single call to Y takes 51 seconds on my machine, so one single call to OF would take approx. 8 and a half hour!!

With the modification you see in the attached picture Y is called only once a one single call to OF takes a bit more than 51 seconds now.

Not sure if this is enough to make the solve block finish in reasonable time - I did not try as I suppose that it still will take quite some time as OF would be called many many times when trying to minimize it. At least it will now be about 580 times faster ;-)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
08:04 AM

02-06-2019
08:04 AM

Re: Optimization problem using minimize function

Thank you very much ! I reduced the number from 583 to 470. I cannot go lower unfortunately. Now it should theoretically calculate the case in 2 hours, since OF for one data gives me the result in 15 seconds.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
09:57 AM

02-06-2019
09:57 AM

Re: Optimization problem using minimize function

Why do you think it should solve in 2 hours?

We do not know how many changes the algorithm used for "minimize" will make and so we don't know how often OF will be called by the algorithm.

I guess you simply divided the 8 hours I mentioned by 4.

But those 8 hours simply were a guess how long it would take for ONE call to OF with the way you defined OF originally.

We can hardly guess how long the solve block would need to finish. The number of iterations done there depends on the algorithm used and is depended on how fast the convergence will be.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
11:30 AM

02-06-2019
11:30 AM

Re: Optimization problem using minimize function

I am sorry I blocked the area in mathcad. I just had so many things there I thought It would be unreadable. I enclose it once again. But still from your experience having such a function with let's say 5 variables would it be possible to obtain the solution within 10 minutes for instance?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-06-2019
01:16 PM

02-06-2019
01:16 PM

Re: Optimization problem using minimize function

@Murarz wrote:

Yes it is possible.

I was just working on it and depending on the interpretation of your function Y it takes 1,5 to 3 minutes ;-)

I was able to speed up your function Y significantly and in combination of the aforementioned speeded up function OF this means that OF will now work with a 50000 times faster speed.

I'll upload the modified worksheet in a few minutes - just have to clean up one thing or another.

I'll upload the modified file in a few minutes.

Top Tags