Skip to main content
1-Visitor
January 9, 2017
Question

Given/Find in function definition doesn't work right - parameters passed in ignored

  • January 9, 2017
  • 5 replies
  • 3387 views

I'm trying to define a function with a Given/Find solve block inside. i.e. the function calls a Given/Find block.

 

I found this thread on how to do it

Embedding Solve block in a function - PTC Community

It had an example file:

https://www.ptcusercommunity.com/servlet/JiveServlet/download/30310-2824/collab%20-%20solve%20block%20demo%2001.mcd

 

The problem I run into is that the values I pass into the function (which is used by the Find block), is ignored. Well, not exactly ignored - I think it uses it like a guess value. It solves the system of equations, but the parameters I passed in are changed.

 

My file is attached.


TIA,
Jason

5 replies

23-Emerald IV
January 9, 2017

First off:

You cannot use an assignment (shows as :=  ) inside a Solve block. In a Solve block you describe constraints, you must use boolean equals (normall a bold =  ).

Luc

23-Emerald IV
January 9, 2017

Then the result of the Solve block should contain all variables you want to solve for:

So after a small rebuild:

All constraints are satisfied.

Luc

JasonC1-VisitorAuthor
1-Visitor
January 9, 2017

There's something not right

This statement

     i0 = iavg - di / 2

is NOT a constraint. It is merely an initial value for the solver. That's why I used := instead of = (bold)
The correct answer is at the bottom of the sheet.  The correct answer for i0 is NOT equal to iavg - di/s

??

JasonC1-VisitorAuthor
1-Visitor
January 9, 2017

Also:
find.png

25-Diamond I
January 10, 2017

If you don't want "i.avg" and "di" to change, you should not solve for them. Just solve for the other 6 variables.

You have 6 variables to solve for, but seven equations. It looks like

is redundant (at least with the equations Ti() and Qt() you provide) and can be omitted. You had done this yourself in your last solve block where you said that the results would be correct. (For some reason you also had changed i.avg from 2.1 to 2 there). EDIT: Just noticed that you had not omitted that equations but that it was hidden underneath the Find region. Nevertheless the equation is redundant, other Mathcad would refuse to find a solution.

As your system is quite simple, you may also consider to solve it symbolically and use the resulting expression which are depending on i.avg, di and the two functions Ti, Qi, to calculate the variables you are looking for.

You would have to go for a symbolic solution before you define your functions and the guess values. Heres the numeric solve block:

25-Diamond I
January 10, 2017

Just read your answer to Luc and that you want the guess value for i.0 to be dependent on the arguments i.avg and di.

This is a little bit tricky and can be done, by turning the solve block into an auxiliary function with three arguments and defining the real function findit to call it with the appropriate guess value:

JasonC1-VisitorAuthor
1-Visitor
January 10, 2017

Werner,

The functions Ti and Qt are placeholders; the actual functions are much more complicated and have no closed form. That was the first thing I tried. This sheet I attached is a much abbreviated, simplified version that illustrates the problem I'm having with the Give/Find block.

I will go and digest your answer now.  Thanks to both you and Luc.

JasonC1-VisitorAuthor
1-Visitor
January 10, 2017

OK this lesson from Werner was the key:
"If you don't want "i.avg" and "di" to change, you should not solve for them. Just solve for the other 6 variables."

I only added it to the variable output list as a short cut to see if it changed it or not. But now I know that actually allows Find to change it.


Also, it looks like placing a guess value using the assignment := operator inside of the Given/Find block is legit.

Lastly, when defining variables before the Given/Find block, it seems the values you assign to them matter, because they seem to be also used as a first guess, even if the equations (bold '=') appear to over-ride them.

Attached is the fixed version, for posterity.

Thanks again all