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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Clueless about solver and intermediate variables

rrogman
1-Visitor

Clueless about solver and intermediate variables

Hi Mathcad'ers,

It's been quite a few years since I last worked with Mathcad, and I don't remember if/how Mathcad could solve a system of equations with intermediate variables.

The sheet that I have put together results in an error for undefined variables if I do not place guess values for the intermediate variable. Do I need to put a guess value for these?
If I do set a guess value, I get an error that "this value must be a function".

What's the best way of addressing this?

The details for the sheet are:

I would like to determine a,b,o,and q as a function of g and s (inputs).

l,t, and p are constants.

j,o1,o2,b1,b2 are intermediate variables.

Thanks for the help,

Raphael

6 REPLIES 6
MJG
18-Opal
18-Opal
(To:rrogman)

I can't open your file, but you likely just need to turn your intermediate values into functions of the variables you are trying to solve for.

For example, if j:=a+b, then make it j(a,b):=a+b.  Then, anytime you use j in an equation, replace it with j(a,b).

rrogman
1-Visitor
(To:MJG)

Thanks Mark,

I tried this approach but i haven't had much success.Most likely because each function is a function of another. Here's the original sheet.Mathcad Sheet.PNG

And a screenshot of the updated sheet- the error now is the initial  guess must consist of scalars and matrices.

Mathcad sheet r2.PNG

Regards,

Raphael

MJG
18-Opal
18-Opal
(To:rrogman)

Raphael,

Your second screenshot does not show the solve block (guess values, constraints, solver on left side).  I assume this just got cut off of your screenshot.

Aside from that, I see a few problems with your setup:

  1. I'm not sure if it's necessary or not, but typically only the variables you're trying to solve are defined in the "guess values" section, and only the inequalities are included in the "constraints" section.  Therefore, you should move the definitions of p, l, t, g, s, d, j, o1, o2, b1, and b2 above the solve block.
  2. Your definition of o1 should be o1(t,d,a).  o1 should not be a function of j since j is not a variable - it is a function.  Similarly throughout your other definitions.
  3. You're solving for 4 variables, therefore you need 4 inequalities.  I'm guessing that your fourth is intended to be o=o1(t,j,d)+o2(p,j,l) instead of your definition of o(o1,o2).

Also, as long as you define j after t & d, there is no need to make j a function of those variables (since you are not solving for those variables).  Your definition of j could simply be j(a):=...  The same goes for your other similar variables.  There is nothing mathematically wrong with the way you have done this, but it would help clean things up.

MJG
18-Opal
18-Opal
(To:MJG)

A few more observations:

Some of your equations still reference j as a variable.  They need to be revised to reference j as a function.

Your definition of b1 and the inequality that starts with q= both have 180 as a constant.  I'm not exactly sure what these equations are supposed to represent, but please note that Mathcad's trig functions have angles in radians.  If 180 is intended to be degrees, you'll need to convert.  Note that the easiest way to "convert" between degrees and radians is to multiply by the unit "deg".

I decided to replicate your calculations and was able to get a result.  However, the solver is very picky about what guess values are acceptable, and the results vary considerably from one guess to another.  Here is one solution:

MJG
18-Opal
18-Opal
(To:MJG)

The solver is much more stable when you multiply the 180's by "deg":

Werner_E
25-Diamond I
(To:MJG)

> The solver is much more stable when you multiply the 180's by "deg":

I don't think that it has to do with stability. You simply get wrong results if you don't.

Apart from the definition of g Raphael forgot that Mathcad uses radiants when calculating with angles.

We could also define g:=0.6 deg

Werner

Announcements

Top Tags