×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

## Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Hi:

I am currently using MathCad for my research and trying the figure out whether MathCad is capable to do my wanted work because it requires a complicated coding logic.
If not, please suggest me the capable software.

The goal is to find an unique answer set of 25 variables:

Now I have an math equation A=M and M contains 25 variables.
"A" is the known data set under different frequencies from the measurement (could be >100).
That means I have >100 data points ("A") to predict the possible answer sets of 25 variables.

In addition, I also have a data library of the variables (under different frequencies) from the measurement.

So the thinking is to find the right combination of the variable from the library to satisfy each "A"
We already expect the multiple solutions.
Therefore 25 initial guess values for the variables will be provided.

We are thinking to use the Solve Block plus Loop/If programming to handle this case?

Does anyone deal with the similar case using MathCad?
Replies continue below

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Hi:

I think it will be clear by explaining the thinking this way.

Now I have a measured data set as the library and then 25 data points will be chosen as the initial guess value in the "M"

Then calculated "A" will be obtained through equation A=M and compared with the measured "A".

If calculated "A" (from the initial guess value) is relatively close to measured "A", the wanted solution is obtained.

If not, another 25 data points (close to the initial guess value) will be chosen from the library to match the measured "A".

I think 25 "A" are needed because I define 25 variable.

The goal is to find the closet solution to the initial guess value from the library we have.

Is it possible to do that in the Mathcad?

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
I am not a good programmer and also don't know how to use the script (VBA?) in Excel.

We are thinking maybe we have to use Matlab to deal with this case.

But we still want to know whether we can use MathCad bcz we are using it now.

For now the manual way is to do it by try and error (that's what I can do for now).

The goal is to build up an automatic way.

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

I don't think you absolutely have to use VBA in Excel to invoke the Solver for this many variables.

As I said, I don't think there is any had limitation in Mathcad that prevents you from setting something like that up, but the more degrees of freedom available, the less likely it is that you can converge consistently to a single solution. There may, or may not, be a bunch of local minima that may cause the solution to bounce around.

TTFN
FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Thanks!! IRstuff..

After the internal discussion, I think my question becomes the optimization problem.

Now the situation is I will use my library (each time choose 25 numbers) to calculate an index set under various frequencies (>>25).

The goal is to find out a data set with the lowest error value.

Absolutely the more constraints I put, the more multiple solutions will be excluded.

I have seen some videos from PTC, talking about the optimization problem of two variables.

I am not sure whether MathCad can read the data from the library by loop and then find out this 25 data set at the same time.

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

You haven't made it clear what you want to do.
I often used the minerr() function to estimate a model from data.
You can see I am estimating a gain, natural frequency, damping factor and offset using the control output to excite the system and monitoring the actual position. The goal is to use the miner function to minimize the error between my model and the data and there are about 1000-2000 data points.

#### Quote:

Now the situation is I will use my library (each time choose 25 numbers) to calculate an index set under various frequencies (>>25).
Are this measured values as a function of frequency? Are you trying to find an equation that will then estimate the measured data as a function of frequency for the 100 sets of measured data?

If so do you have an equation that you are going to use as a function of frequency? For instance this function could be simple like x(omega)=(b1*s+b0)/(s^2+a1*s+a0) where you substitute j omega for s. The minerr function would find b1,b0,a1 and a0 so that the error between this transfer function and the measure response would be minimized.

Peter Nachtwey
Delta Computer Systems
http://www.deltamotion.com

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Hi PNachtwey:

My question is close to your but has some differences.
We are also discussing about using minerr() function.
Let me explain my question more detail.

The goal of my question is to find one closest data set with 25 variables to approach the measurement result.

To do that, first I will have two libraries (say A and B) ready.
The data in these two libraries is as a function of frequency.
For example, library A has 100 variables. Each variable has a value column as the function of frequencies and the same in library B.

Then in every loop I will select 25 numbers from both libraries to form complex numbers.
At this moment I will have 25 complex variables with 25 value columns as the function of frequencies.

Then I input these 25 value columns into the transfer matrix (contain 25 matrix) equation to calculate the data.
Each variable is for one matrix. Equation is just C=M, M is the transfer matrix.

C will be the data as the function of frequencies (frequencies will be the same in the library).

Finally the calculated C will be compared with measured C through minerr() function to determine values of 25 variables.

The initial guess values (1st loop 25 variables) are chosen from the calibrated measurement.

Therefore we want to know when we obtain a new measured C, can we find a proper 25 variables through libraries to achieve the best approach.

So I just don't know whether MathCad can do this and how....

Have you dealed with this kind complicated thing?

I have thought of using the stupid way (means calculate all possible combinations to judge) but maybe doing something in a smarter way is better.

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

I'm still not sure what the concern really is. Minerr does all the calculations for you, and finds a set of values that minimizes your error function. Whether or not your error function is well-behaved is a wholly separate question. There may be multiple solutions with similar errors. It would be up to you, as is always the case, to determine whether the resultant solution is even valid.

TTFN
FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Hi IRstuff:

Thanks!!

My concern is: how to tell the Minerr function to continuously pick up variables from the library after 2nd loop to find possible solutions. That means the values for the internal calculation are not arbitrary.
From all examples I read, Minerr function use the built-in algorithm (LMA) to decide variables in the internal calculation, not pick up variables from somewhere.
That's where I get trouble.

But I am also thinking of another route.
Since the initial guess value I will put is a calibrated value, I can use the general Minerr function way to find possible solutions.
Then compare variables in the solution with variables in the library to find the best approach (2nd Minerr function).

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

I can't make any sense of your terminology or your problem statement or your problem approach. I can't even tell if you are mistakenly thinking that you need to manually iterate minerr, which you don't

The best I can do is to describe the Solve block process, which applies to both Find and Minerr.

> guess values for the solve block
Given
> some function that processes the guess values that should result in what you are trying to match (you use <CRTL> + "=" between the two, i.e., f(x) <CTRL>= match constraint

or you can assign it to a function of other variables, g(y) := minerr(x)

TTFN
FAQ731-376: Eng-Tips.com Forum Policies

Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Does anyone use Solve Block plus Loop/If programming to solve multiple variables case?

(OP)
Hi IRstuff:

I have written the code using Solve Block and I understand the way of using minerr function is quite similar.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!