Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

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

Status
Not open for further replies.

cxj3994

Electrical
Jun 26, 2013
7
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

Recommended for you

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?
 
Theoretically, yes, it's possible. I've never tried anything that large in the solve block. Have you considered Excel?

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
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.



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

Need help writing a question or understanding a reply? forum1529
 
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.

 
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.

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
 
Hi PNachtwey:

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.

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

Need help writing a question or understanding a reply? forum1529
 
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).




 
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

> you can explicitly ask for the answer minerr(x) :=
or you can assign it to a function of other variables, g(y) := minerr(x)

TTFN
faq731-376
7ofakss

Need help writing a question or understanding a reply? forum1529
 
Hi IRstuff:

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

Thanks for your mentioning.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor