Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Using Solver in a For Loop

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
01:57 PM

07-26-2016
01:57 PM

Using Solver in a For Loop

Hi,

I'm trying to solve fairly simple equations element by element in an array and from what I've read here it looks like a For loop calling a solve function is the way to go. I know I can't have a Given/Find in a For loop and have to write the function elsewhere and call it from the loop, but I'm having trouble getting that to work I found a lot of discussion on here about this, but none that I have been able to implement. I have attached both the file I'm working on and a simple example of what I'm trying to do that I think will be easier/faster to work on, then I can modify the actual file.

I've been tasked with converting some calculations from Excel to Mathcad 15, and I'm new to Mathcad so learning as I go.

Thanks much in advance for your help.

Labels:

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:17 PM

07-26-2016
04:17 PM

Re: Using Solver in a For Loop

You have to turn the solve block into a function dependent on the variables you would like to change in your loop. In case of your simplified version these are the indices i and j:

I haven't looked at you other file. Hope you can get it to work. If not, come back an ask again.

Regards

Werner

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:30 PM

07-26-2016
04:30 PM

Re: Using Solver in a For Loop

You don't need a solve block for the first--just matrix math

The second (insulation) I've adjusted--you need to make functions of all the variables you want to change. (I couldn't figure out where temperature change came in.)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:32 PM

07-26-2016
04:32 PM

Re: Using Solver in a For Loop

See attached examples. There are multiple ways to skin a cat.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:35 PM

07-26-2016
04:35 PM

Re: Using Solver in a For Loop

Now I was curious and had a look at your other file.

There is more work to do here.

Your solve block obviously should be dependent on three variables, D.pipe, ID.pipe and T.operating.

So ALL functions/variables which take part in the terms used in the solve block must be functions dependent on those three variables (only the variables which are actually used, beginning with

and ending with the solve block

R is flagged red because I had not changed the whole worksheet and I also have not checked if both h.cond_surf and h.cond really are dependent on all three variables.

The solve block is then called that way:

Regards

Werner

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:39 PM

07-26-2016
04:39 PM

Re: Using Solver in a For Loop

Guess you missed a function or two.

E.g. h.cond depends on h.lag , h.lag depends on R.out and R.out depends on the variable D.pipe.

h.cond_surf is dependent on the variable T.operating

...

I was too lazy to look further 😉

Werner

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
04:54 PM

07-26-2016
04:54 PM

Re: Using Solver in a For Loop

Thanks much for your advice, I think I know what to do now. Let me give it a try and report back!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
05:21 PM

07-26-2016
05:21 PM

Re: Using Solver in a For Loop

Thanks again, I've got a lot of checking to do, but I'm finally getting the table output I was looking for!!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2016
07:39 PM

07-26-2016
07:39 PM

Re: Using Solver in a For Loop

Hi.

In the attached, a try for your request.

Two observations. There are an orfan equation, in yellow. Also, your test range is extense, and the solver fails because the guesses. For that, you must to implement some recursion for the guess values, and the final result could be look more than a finite element technique.

Best regards.

Alvaro.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-27-2016
05:24 AM

07-27-2016
05:24 AM

Re: Using Solver in a For Loop

I guess here is what you were trying to do.

Using the guess value TH.i=4,59 in, the solve block fails for the first five diameters at 200 °F.

Fortunately changing the guess to 2 in makes the whole table work OK:

If we weren't able to find a guess which satisfies all combination of input values, we could have made the guess an additional argument of the function R and would have to find a way to precalculate a suitable guess depending on the three input values.

Regards

Werner