## 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?

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?

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

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?

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?

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?

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?

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?

I often used the minerr() function to estimate a model from data.

http://deltamotion.com/peter/Mathcad/Mathcad%20-%2...

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.

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?

Thanks for your post.

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....

Your file contain similar code.

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?

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?

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?

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

> you can explicitly ask for the answer minerr(x) :=

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

FAQ731-376: Eng-Tips.com Forum Policies

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

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

Thanks for your mentioning.