Fminsearch - hold a variable constant

In summary, the conversation discusses the use of the fminsearch function in Matlab to minimize variables while keeping others constant. The user is designing a GUI for a program that involves seven different codes, one of which opens a file for comparison. The user wants to be able to send a filename through fminsearch, but is unsure if it is possible to send a four variable vector while only varying three of the variables. The conversation concludes with the user providing sample files and thanking the expert for their help.
  • #1
jimpx
7
0
Hello,

I want to pass a number of variables through fminsearch. Because of the structure of the program, some of those variables must be held constant while the others are minimized. Is there a way to do this with fminsearch, or is there another minimization program which allows this?

Thanks,

jimpx
 
Technology news on Phys.org
  • #2
I want to pass a number of variables through fminsearch.

Well, an array will do, won't it?
If you can give me more details on what fminsearch is all about, I may be able to help you better.

some of those variables must be held constant while the others are minimized.

Duplicating the array into another temporary array will do the trick, won't it?


Eus
 
  • #3
Thanks for the reply Eus.
Unfortunately that won't work. I am designing a GUI for a program already written. The program calls on 7 functions, sending three variables to the first function, which returns six variables, two of which go to the second and three to the third etc. The GUI sends the three initial variables to the main program which minimizes the answer and returns a result.

I want to send a filename to the main program which will send it to the 6th function to compare. However, if this function is to receive the filename, it will have to receive it at every stage of the fminsearch loop, so I will need to keep the filename from being varied.
Thanks again,

Jimpx
 
  • #4
I am designing a GUI for a program already written.

How does the GUI communicate with the program? By just invoking the program with a command-line? For example, if the user clicks a run button, the GUI will invoke something like this: execve ("program_name", list_of_args, list_of_envp);
Or, by using the API of the program?

sending three variables to the first function, which returns six variables

How does the program return the six variables? Is it in an array or in an environment variable?

I will need to keep the filename from being varied.

A good program should not modify the argument passed into it.
So, if the program follows that principle, you should not need to worry about the filename being modified.

If you are willing to give more details on the environment in which the program is run, the mechanism of communication between your GUI and the program, and the details of the fminsearch, we may help you better.


Eus
 
  • #5
Thanks again for your help Eus,
I will try to explain the environment a bit better.

The original program takes in three variables which are plasma parameters, and calculates the expected spectrum based on these variables. This calculation requires a total of seven different codes, which send and receive certain variables. One of these codes opens a file, which is an experimental spectrum, and compares the calculated with the experimental. A graph is plotted.

To match the calculated spectrum with the experimental, fminsearch is run. It minimizes the difference between the two and returns three variables which closely match with the experimental spectrum.

All of the above runs fine.

However, to implement the GUI, more than just the three variables must be sent. I want to create other options in the GUI, most importantly the option of choosing a file to compare the spectrum with.

However, to send a filename I will have to do it via fminsearch, since the code that compares the calculated and experimental is not the main program but one of the seven in the loop. Hence I need to be able to send the filename as part of a vector which will now hold 4 variables. Can I send a 4 variable vector through fminsearch but only vary 3 of the variables? I can send the files if you want a closer look. Thanks again,
Jimpx
 
  • #6
jimpx said:
However, to send a filename I will have to do it via fminsearch, since the code that compares the calculated and experimental is not the main program but one of the seven in the loop. Hence I need to be able to send the filename as part of a vector which will now hold 4 variables. Can I send a 4 variable vector through fminsearch but only vary 3 of the variables? I can send the files if you want a closer look. Thanks again,
Jimpx

Of course you can send in four variables vector through fminsearch (I assume that the program is written in C/C++).

But, will the function that eventually opens the file know whether there is an extra variable in the vector that is passed into it? If it doesn't know anything about the extra variable, you cannot tell the function to open a different file than usual, can you?

What I want to know is how that function that opens the file know what file it is supposed to open. Does the filename hard-coded in the function definition? If not, how could the function what file it should open?

Yes, please send the files.


Eus
 
  • #7
fminsearch prob

The code is written in Matlab. If you run RunsakkaGUI there should be two plots. The one on the left will work, as its only a single run of the program. The one on the right works, but only with the file that's written into the minimization code. I have included two sample files. Thanks,
jimpx
 

Attachments

  • jimpx.zip
    39.4 KB · Views: 191
  • data_300ns_rightFive.txt
    2.9 KB · Views: 245
  • #8
try sigma_1 = 1e3, N_2b = 1e19, N_e0=1e24
 
  • #9
I have never used MathLab before.
Therefore, I think I cannot help you further.
I hope someone else in this forum can help you with that.


Eus
 
  • #10
Thanks a lot for your help anyway Eus, it's much appreciated.
 

1. What is Fminsearch?

Fminsearch is a function in MATLAB that is used for finding the minimum value of a given function. It uses the Nelder-Mead simplex algorithm, also known as the amoeba method, to search for the minimum value.

2. How do you use Fminsearch to hold a variable constant?

To hold a variable constant in Fminsearch, you can use the "options" argument and specify the constant variable using the "TolX" parameter. This will prevent the algorithm from changing the value of the constant variable during the search.

3. Why would you want to hold a variable constant in Fminsearch?

In some cases, you may have a function with multiple variables and you want to find the minimum value for one variable while keeping another variable at a fixed value. Holding a variable constant in Fminsearch allows you to do this and find the minimum value for the other variable.

4. What happens if you do not hold a variable constant in Fminsearch?

If you do not hold a variable constant in Fminsearch, the algorithm will search for the minimum value by changing all the variables. This may result in a longer search time and may not give you the desired minimum value for the variable you wanted to hold constant.

5. Are there any limitations to using Fminsearch to hold a variable constant?

Yes, there are a few limitations to consider when using Fminsearch to hold a variable constant. One limitation is that the algorithm may not always converge to the minimum value, especially if the function is complex or has many variables. Another limitation is that if the constant variable is too close to the true minimum value, the algorithm may not be able to find it.

Similar threads

  • Programming and Computer Science
Replies
10
Views
1K
Replies
34
Views
1K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
7
Views
441
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
1
Views
6K
Replies
63
Views
3K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
13
Views
1K
Back
Top