Fminsearch - hold a variable constant

Click For Summary

Discussion Overview

The discussion revolves around the use of the fminsearch function in MATLAB for optimization, specifically addressing the challenge of holding certain variables constant while minimizing others. Participants explore the implications of integrating a filename into the optimization process within a graphical user interface (GUI) context.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested
  • Homework-related

Main Points Raised

  • Jimpx seeks to understand how to pass multiple variables to fminsearch while keeping some constant, particularly a filename needed for comparison in a function.
  • Eus suggests that duplicating the array might allow for holding certain variables constant, but Jimpx indicates this approach is not feasible due to the program's structure.
  • Jimpx elaborates on the program's workflow, detailing how it processes plasma parameters and compares calculated spectra with experimental data.
  • Eus questions how the function that opens the file would recognize the extra variable in the vector passed to it, raising concerns about the function's ability to handle the filename correctly.
  • Jimpx confirms the code is written in MATLAB and provides additional context about the GUI and its interaction with the program.
  • Another participant suggests trying specific values for the variables, indicating a potential approach to the optimization problem.
  • Eus expresses a limitation in helping further due to unfamiliarity with MATLAB.

Areas of Agreement / Disagreement

Participants express differing views on how to effectively manage the inclusion of a filename in the optimization process. There is no consensus on the best approach to achieve this within the constraints of fminsearch.

Contextual Notes

The discussion highlights the complexity of integrating additional variables into an optimization routine while maintaining the integrity of the data being processed. Specific assumptions about how functions handle variable inputs remain unresolved.

Who May Find This Useful

Individuals working with MATLAB for optimization tasks, particularly in the context of GUI development and data comparison in scientific applications, may find this discussion relevant.

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.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 34 ·
2
Replies
34
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
12
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
Replies
63
Views
6K
  • · Replies 9 ·
Replies
9
Views
5K