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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

16-Pearl

## Successive solve blocks

I have a few questions for our resident experts.  I am working on a sheet that I'd like to have use multiple solve blocks.  The first block feeds results to the second block.  While I can do it - I wonder if there isn't a simpler way.  It's rather cumbersome to set everything up this way.

I'm also curious about how MC works in regards to solving - as it seems sluggish.  Is MC solving the same solve block over and over every time I call the functions (e.g. When I solve for L(alpha) and K(alpha) does it solve the 2nd block twice and the first block 4 times)?

Here's a picture of a very simplified version.  MC4.0 attached.  (note: actual sheet is 18 pages with dozens of variables and I'm using multiple blocks because using one block has become unmanagable.  It also allows me to use existing calculation templates without merging calculations.)

Is there a better way?

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(To:DJF)

@dferry wrote:

Yes that's even better.

I think I'd rather prefer the first variant, but I guess you will like the third one here 🙂

Is there any way the find command could be broken up with matrices or similar to shorten it.

I don't think so. "Find" won't accept vectors or vector elements as arguments.

But I waas surprised as of the error message we get. How would we use a function as argument in the find command??

15 REPLIES 15
23-Emerald I
(To:DJF)

I don't know of a different way.

24-Ruby V
(To:DJF)

Get rid of the fundtions Y and G

The argument of the second solve block should rather be a 2-element vector (and used accordingly)

The call should be ans2(ans(b))=...

Thus avoiding the repeated call of the first solve block.

Functions K and L still call the solve block twice which is not efficient but the only way to get around this is to use a vector theta (rather than a range) which is fed in ans2(ans(theta)) and the result will have to be separated in two vectors K and L. A lot of work to avoid the double call of the block, so I have not implemented it below:

> (e.g. When I solve for L(alpha) and K(alpha) does it solve the 2nd block twice and the first block 4 times)?

Even worse! When you evaluate L(2) then the 2nd solve block ist evaluated once and when you evaluate K(2) the same calcuation is done again (unneccesary, but I can't think of avoiding this if you need distinct functions K and L.

Oc course you could always use something like stack(K,L):=ans2(2). to get the values with just one call to the solve block.

BUT .... whenever you evaluate L(2) the way you had set it up the first solve block ist called twice with every iteration the second block does. If (for a more complex constraint) each block needs 50 iterations to get its result, L(2)=  would call the first solve block 100 times!

For the plot of L(theta) the first solve block would be called 2100 times.

With my modification L(2) calls the first solve block only once and plotting L(theta) calls it 21 times.

16-Pearl
(To:Werner_E)

Thanks Werner.  Seems like there is no good solution.  If I set it up your way it's faster, but I wind up having to call variables "vector [ subscript" instead of something meaningful like "Velocity" & "Pressure" - kind of defeating the readability of a mathcad file and making future changes difficult.  But doing it my way I'm re-solving things many, many times.  sigh.  I think I'll just do it my way as my baseline calculation & documentation - and then transfer everything to a different program to solve it quickly.

23-Emerald III
(To:DJF)

You don't show the full problem, I accept that....But:

Is there no way to solve your individual problems analytically (symbolically), thus avoiding the solve-block hassle...?

Luc

16-Pearl
(To:LucMeekes)

I'm quite certain there isn't.  The full calculation (like i said, 18 pages of stuff - although most of that isn't in the solve blocks) solves for flow through multiple or-if-ices in series, reads coefficients from look up tables, and solves a free body diagram.  It it's possible I don't think it's worth the effort.  I have other programs I can use, but I do like some of the MC advantages.  It's just not a good problem for it, I think.

24-Ruby V
(To:DJF)

@dferry wrote:

Thanks Werner.  Seems like there is no good solution.  If I set it up your way it's faster, but I wind up having to call variables "vector [ subscript" instead of something meaningful like "Velocity" & "Pressure"

Not necessarily - see here a slightly different appraoch which avoids the vector and uses freely named variables as you demand:

16-Pearl
(To:Werner_E)

Yes!  I think this is what I'm after.  I'll have to try it out, but I think you've come through again, Werner.  Much appreciatied as always.

-Doug

24-Ruby V
(To:DJF)

You are welcome.

I played around and came up with  a slightly different approach. I was surprised it worked 😉

16-Pearl
(To:Werner_E)

Yes that's even better.  Your approach makes me curious if another long standing problem can be solved along these lines.  Let's say instead of l & j, we had 20 variables and the 'find' line was really long.  Is there any way the find command could be broken up with matrices or similar to shorten it. I'm ok with more vertical space, but I run out of page width. (And no, the 4.0 line break doesn't work, since there is no operator on which to break)

24-Ruby V
(To:DJF)

@dferry wrote:

Yes that's even better.

I think I'd rather prefer the first variant, but I guess you will like the third one here 🙂

Is there any way the find command could be broken up with matrices or similar to shorten it.

I don't think so. "Find" won't accept vectors or vector elements as arguments.

But I waas surprised as of the error message we get. How would we use a function as argument in the find command??

16-Pearl
(To:Werner_E)

Yes, I like that even better - much cleaner and clearer.  As an exercise I made sure it works for multiple solve blocks. Not surprisingly, it does just what it's supposed to.

Thanks again.  This is a POWERFUL tool imho.  Definetly saving this one.

16-Pearl
(To:DJF)

And for good measure - the solve block inputs can be functions as well

24-Ruby V
(To:DJF)

@dferry wrote:

And for good measure - the solve block inputs can be functions as well

"ans" was a function, too, in the examples above 😉

But you can really make a function an argument of the solve block function:

or

Many ways to play around with that principle

16-Pearl
(To:Werner_E)

The next step for me is to develop plots.  I certainly want to avoid calling the solve blocks more than necessary.  I came up with this method, but maybe there is something more efficient.  I can't be sure, but I think the program at the bottom solves ans3 once for each step, then writes the output into vectors, and then moves on to the next step.  So, if I have 10 steps I only need 10 solutions performed.

Or, I think it should NOT be done as follows:

Am I correct in thinking that this graph solves the block 11 times for LL, then repeats it another 11 times for KK?  And if I made another graph with LL in it, it would solve it yet another 11 times?  Or is Mathcad smarter than I think.

Thanks,

24-Ruby V
(To:DJF)

@dferry wrote:

Am I correct in thinking that this graph solves the block 11 times for LL, then repeats it another 11 times for KK?  And if I made another graph with LL in it, it would solve it yet another 11 times?  Or is Mathcad smarter than I think.

Thanks,

Yes, you right. Thats the price for more flexibility you have with functions.

I guess its a fair price and usually this does not really matter that much.

The main problem was that the second solve block called the first one overe and over again for each iteration it made and did that for every single point in the plot.

This really slowed down calculation significally.

Announcements
Top Tags