cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

"Find" Solve Block - How to change the guess values for a solve block

mnori
12-Amethyst

"Find" Solve Block - How to change the guess values for a solve block

I use "Find" in a Solve Block in order to solve a system of non linear equations. I would like to change in auto-mode the guess values in order to solve the system for different values of the model parameters. How could I change the solution guess values for the solutions? Is for instance possible to include a solve block in the for loop of a code? Could you suggest a possible method?

1 ACCEPTED SOLUTION

Accepted Solutions
AlanStevens
17-Peridot
(To:mnori)

This illustrates how to use the function argument to supply a guess value:

root.PNG

Alan

View solution in original post

8 REPLIES 8
StuartBruff
23-Emerald II
(To:mnori)

Massimiliano Nori wrote:

I use "Find" in a Solve Block in order to solve a system of non linear equations. I would like to change in auto-mode the guess values in order to solve the system for different values of the model parameters. How could I change the solution guess values for the solutions? Is for instance possible to include a solve block in the for loop of a code? Could you suggest a possible method?

Yes, it is possible to change the parameters from within a loop.  To do this, you need to make a function from the Find.

Let's say that you have a parameter a that you wish to alter on each call to the solve block and you want to find a variable x.  Instead of result:=Find(x) you would type f(a):Find(x) and then assign the results as you would any other function result, eg result:=f(2) (where 2 is a particular value of a).

Look up Solve blocks and parameters in Help.

Stuart

mnori
12-Amethyst
(To:StuartBruff)

Hi Stuart,

thank you for your answer. I knew about the possibility to recall the function for different values of the parameter as you shown. My question is about the guess value for the solution. To my understanding , the solve block guess ( or initial ) values for the solution.are defined only before the solve block.

AlanStevens
17-Peridot
(To:mnori)

This illustrates how to use the function argument to supply a guess value:

root.PNG

Alan

I learned something new today.  Thanks for sharing.

While playing around with this, I found something odd.  Any thoughts?  For reference, this is using v15.

StuartBruff
23-Emerald II
(To:MJG)

Mark Gase wrote:

I learned something new today.  Thanks for sharing.

While playing around with this, I found something odd.  Any thoughts?  For reference, this is using v15.

Your solve block is trying to make the vector of results equal to zero and not just each individual value. It would seem as though the solver steps don't bring it close enough to the 'correct' solution when it's trying to get all of the solutions in one hit.  Vectorize the call to fn to get the results you are expecting.

Stuart

Your solve block is trying to make the vector of results equal to zero and not just each individual value. It would seem as though the solver steps don't bring it close enough to the 'correct' solution when it's trying to get all of the solutions in one hit.  Vectorize the call to fn to get the results you are expecting.

This makes sense.  Thanks for the response.

On another side note:

In my Mathcad document, I called the fn functions with 4x1 matrices as the argument - as shown in the image I included with my post.  However, after saving the file and re-opening it (or if you open the file that I attached above), the functions are called as if the four matrix elements were four separate arguments.  What caused this?

StuartBruff
23-Emerald II
(To:MJG)

Mark Gase wrote:

Your solve block is trying to make the vector of results equal to zero and not just each individual value. It would seem as though the solver steps don't bring it close enough to the 'correct' solution when it's trying to get all of the solutions in one hit.  Vectorize the call to fn to get the results you are expecting.

This makes sense.  Thanks for the response.

On another side note:

In my Mathcad document, I called the fn functions with 4x1 matrices as the argument - as shown in the image I included with my post.  However, after saving the file and re-opening it (or if you open the file that I attached above), the functions are called as if the four matrix elements were four separate arguments.  What caused this?

Yes, Don't Know what caused it but I did notice it when I opened your file ... I was rather wondering why I could only see one set of parentheses/brackets on your image. I was expecting:  

(I've used the Prefix operator in the second case to evaluate the expression, but there's small gap between fn and the vector that isn't present in your image and that made me think you hadn't used it)

It was just easier for me to stick a stack around the fn argument than convert back to vectors.

Stuart

You're right: using only one set of brackets caused the issue.

Obviously it's not useful since you can't save it this way, but to call the function with the one set of brackets:

- Enter the function as you show above with two brackets

- Delete the outer set of brackets and subsequent empty placeholder (place courser to the right of "fn" and hit delete twice).

I did this to give it a "cleaner" look (subjective, I know).  I could swear I've done this before without problem.  I'll have to see if I can find any old examples because I tried a few methods and can't get anything to work (not that it really matters anyway, though).

Top Tags