want to do optimization with fmincon but without having exact function

5 views (last 30 days)
Hi,
I want to do an optimization for constrain problem and use fmincon.
The problem is that, I don't have function that be defined by variables like f(x,y)=x^2+y^2
I have FEM model which is contain a file with thousands of line in bdf format, which is as input for MSC.NASTRAN
I cloud read my design variable from that file and store them in parameters, as well as write new value on the specific place. Then I will call MSC.Nastran to do computation and then generate f06 file, which the value of objective and constrains are stored in that and read these value and store them in parameters too.
I want to use fmincon to do optimization for my problem but it gives me error which i think this is due to calculation of gradient of function, because for 10 variables problem it do 11 calculation and then error appear.
Thanks so much in advanced.
  4 Comments
Walter Roberson
Walter Roberson on 16 Oct 2020
Dorsa Haji Ghaffari:
What you have defined so far would be satisfied with an objective function that returned -inf no matter what the input was.
Given a set of times and any associated measurements so far and a list of trial model parameters, then how would you compute the current objective function value?
As time progresses, are you hoping to refine the parameters (the uncertaintly gets lower as you have more data), or are you hoping to update the parameters (the parameters are changing in time) ?
mohammad haghnejat
mohammad haghnejat on 16 Oct 2020
Hi Dorsa,
I did.
To do optimization, any optimization algorithm needs value for a cost function. It can be obtained from a mathematical equation in a code, or from other techniques.
If you want to use other simulation tools, you need to do these steps:
This is a procedure for func.m
For instance, the function z = Func(X)
X is input from fmincon
1-Your code needs to be able to build a file that assigns X in a way that software can use it.
To assign X to the input, fopen, fseek, and fwrite maybe useful
2-Run the software with the system command,
3-When the calculation is done, an output that can be read in the matlab must be produced.
fopen and textscan maybe useful in this section
I hope you get the idea.
If I can be of assistance, please do not hesitate to contact me

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Dec 2017
Your function diflecti failed when it tried to fopen() a file for reading. You should be using something similar to
BDF_filename = 'BDF_FILE_NAME_GOES_HERE';
[fidInBDF, msg] = fopen(BDF_filename);
if fidInBDF < 0
error('Failed to open BDF file "%s" because "%s"', BDF_filename, msg);
end

More Answers (1)

mohammad haghnejat
mohammad haghnejat on 16 Dec 2017
thanks so much, I think I fix my problem.
Thank so much,

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!