Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing "Given" solve blocks into loops

Status
Not open for further replies.

CDR

New member
Jun 27, 2001
6
0
0
NL
I was wondering if there was a way to place a Given sove block within a while loop or for loop. For instance, I would like to solve:

For x = 1-9

Given

f(x,a) = h(x,a)

Find(a)


Typically, I would just enter in x as a vector of numbers, however the system of equations I want to solve for is quite complex and does not permit vectors of data to be inputted. Thus I am restricted to having x = a constant. This means I have to vary x by hand and record the results of a by hand. This is not very robust, and I know there has to be an alternative way. Any help would be great.

CDR
 
Replies continue below

Recommended for you

I'm curious, why can't you use vectors? I have encountered such situations, but the solution usually depends upon why vectors can't be used. The most common solution is to use the vectorization operator (it produces an ->) above the variable. This forces a parallel compution method instead of matrix algebra.

HTH,
Imagineer


 
I am aware of the vectorize operator, and that could solve my problem. The problem is I am using a database of formulas programed into mathcad which were not set up to hgandel vectors in the first place. I could edit all of the equations, however since this database containes over 150 pages of mathcad code, it would be desirable not to have to modify them. Using the "Given" solve block solves what I need very well for a single input value, I just thought that if there were a way to iterate a "Given" solve block that I could save myself the time of having to modify the entire database of equations, or prevent me having to repeat the solve block manually.

CDR
 
Hi CDR,

I ran into the same problem. I had a set of 3 non-linear equations that I needed to solve. However, the solutions to the set was heavily dependent upon the initial values you input as guesses.

To get around that problem, I needed to automate the selection of guess values I used as inputs. My solution is as follows. If anyone else has a more efficient solution, please let me know!

Install VisSim -- it came on the Mathcad 2001 installation CD. It allows you to insert Mathcad object blocks and connect them using signal wires.

Insert a Mathcad object. You will need to assign your input values from the internal variables in0, in1, in2, etc to your guess variables of your Find() block. Starting from the top, the black arrows on the left side of the Mathcad block represent in0, in1, in2. You can add or delete inputs (and outputs) so that you have as many as you need. Your mathcad object should save your data to a file. I changed my filenames to reflect what input values I used.

Next, insert a file input block for each variable. Connect the file input blocks to the mathcad object. You may have to format your data into 2 columns -- leftmost column is the time (in the simulation) that the data is sent through the wire. The second column is the data that you want sent.

You may need to put a dummy line at the end of your mathcad block that says 'out0 := 1' or something, and put a display block connected to the output. This will make VisSim completely process your entire Mathcad file before it goes on to the next time value. Also, the mathcad server may become busy and you'll have to continue pressing enter.

Then once you get your data files, you can import the data into Mathcad with the READPRN command (or a file input object) and process it from there.

This process is quite lengthy and cumbersome but it is the only way that I have found that will work.

If anyone from Mathsoft is reading out there, PLEASE PLEASE work on supporting Given-Find blocks in the Mathcad programming loops in the next version!! (For you newbies out there, try typing in the word 'Given' into the first line of a programming structure and watch Mathcad crash and burn.....)

Hope this helps,
Matt
mattman206@hotmail.com



 
It sounds to me as though you should create a function
usign the Given-find block solver, then access the function
using a loop inside your MathCAD program.
 
Status
Not open for further replies.
Back
Top