Skip to main content
14-Alexandrite
January 3, 2021
Solved

Define functions

  • January 3, 2021
  • 3 replies
  • 7735 views

Hello everyone,

In the attached worksheet, I would like to define the Shekel family of functions using Mathcad.

I am stuck here. I can’t find the error, help me.

I appreciate it if you share your idea and advice on this worksheet.

All the best,

CarlosRomero

Best answer by Werner_E

@Fred_Kohlhepp wrote:

I think my computer has covid19   ðŸ˜‰

 

Edited post to try to reinsert the picture.


Maybe its not Covid-19 but just Khoros 😉

@Fred_Kohlhepp 

I very often experience problems when embedding pictures. After copying a picture there would be created some html-code (you can switch this editor to html mode to see it) but no picture is displayed.

The html code inserted is something like

<div id="tinyMceEditorWerner_E_0" class="mceNonEditable lia-copypaste-placeholder">&nbsp;</div>

but should be something like

<p><li-image width="400" height="400" alt="Werner_E_0-1609793680999.png" align="inline" id="35549iF3DB80055CF6FD40" size="medium" resized="false" sourceType="new"></li-image></p>

Only solution is to post the message and immediately after that open it again for editing and usually it would let you embed pictures as it should be. Guess you ran into the very same bug. EDIT: It just happened to me here again when trying to insert the first pic.

@Jaime_Lee  Is this an already known forum bug? It can't be reliably reproduced but happens quite often. I am not sure what this bug depends on - length of text, time being online, time having the posting open under development, current zodiac sign, ... ?

 

@CarlosRomero 

Its noticeable that all the three minimum values given in the text are a bit smaller than the ones we can actually achieve with the function. I can't say where those values would come from, but with the table values given they can't be calculated. Also the function values at (4,4,4,4)^T always are a bit larger than the minimum values found, so Mathcad is correct at returning those values which are slightly off the (4,4,4,4)^T.

Werner_E_0-1609785953830.png

BTW, instead of using a genetic algorithm you may give "simulated annealing" a try.
Richard had provided a fine implementation here: https://community.ptc.com/t5/PTC-Mathcad/Minimizing-a-Function-using-Simulated-Annealing/m-p/445213/highlight/true#M176579

I copied his functions into the attached worksheet to give it a try

Werner_E_1-1609786271885.png

 

 

 

 

 

 

3 replies

23-Emerald I
January 3, 2021

Try this

Fred_Kohlhepp_0-1609703395065.png

Fred_Kohlhepp_1-1609703441900.png

Saved in Prime 4 below.  (Sorry, don't have 15)

 

23-Emerald IV
January 3, 2021

How about:

LucMeekes_0-1609710537317.png

 

Success!
Luc

25-Diamond I
January 4, 2021

Even though your function is a bit cumbersome, it is easy to repair. You have overlooked that in the text the first index of a_i, j denotes the column and not the row. This can be easily repaired, either by transposing the matrix M or by swapping the two indices in the formula (as can be seen in the picture).

It also would be easier to define c transposed, this way you can avoid the index 0 at c.

Werner_E_0-1609734757546.png

As you have seen by the answers of Fred and Luc, its more clear and elegant to define the matrix as an array.

Luc also provided a single function for all three Shekel functions which is also ORIGIN-aware.

His result differs because he missed the leading minus sign and forgot to square the summands:

Werner_E_0-1609737449371.png

 

Fred used Primes table feature (not available in real Mathcad) to build the matrix. Note that he had set the system variable ORIGIN to 1 and also transposed the matrix a, so he could use the very same indices as in the text. His result is different because he mistakenly included the c_j in the sum.

 

Werner_E_0-1609735202665.png

25-Diamond I
January 4, 2021

Here is a slight modification of Lucs implementation

Werner_E_0-1609759285232.png

 

Or, to be even closer to the notation of the formula in the text

Werner_E_1-1609759322144.png

 

 

 

14-Alexandrite
January 4, 2021

Thanks Fred, Luc and Wernner for your advice and good answers.

I applied a genetic algorithm to the shekel functions given by Fred to find the global optimum and it gives me values of the four parameters x1, x2, x3, x4 approximate to the answer indicated in the book of Zbigniew Michalewicz; that is 4, 4, 4, 4. But the value of the functions are not equal to s3min = -10.15320, s4min = -10.402820 y s5min = -10.53628; otherwise they give me values like the ones shown in the attached image.

 

Do you have any ideas to fix this problem?

Big thank.

Carlos Romero.shekel_test1_ answer.jpg