Fminsearch - hold a variable constant

AI Thread Summary
The discussion revolves around the use of fminsearch in MATLAB to minimize variables while keeping others constant, specifically in the context of a GUI designed for an existing program. The user, Jimpx, seeks to pass a filename as one of the variables in a vector of four, while only minimizing three of those variables. The challenge arises because the filename must be consistently passed through multiple function calls within the program's structure. Participants suggest various approaches, including the possibility of sending an array of variables and the need for the function that opens the file to recognize the extra variable. Ultimately, Jimpx confirms that the program is written in MATLAB and shares that the GUI can run successfully with certain parameters, but struggles with integrating the filename into the minimization process. The discussion highlights the complexities of variable management in function calls and the need for clear communication between the GUI and the underlying program logic.
jimpx
Messages
7
Reaction score
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
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
 
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
 
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
 
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
 
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
 
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

try sigma_1 = 1e3, N_2b = 1e19, N_e0=1e24
 
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.
 
Back
Top