- Define your function.
- Create a function to calculate the difference between your data and the 0.5 contour level.
- Use fmincon to minimize this difference and find the optimal input variables.
Fitting specific level of contour plot to data
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I have some data (shown in yellow and blue dots) and I want to fit a specific level (0.5) of a contour plot of a function to it. The function has 6 input variables and what I want to do is to find the set of input variables resulting in the optimum fit of the 0.5 contour plot of the function to the data. Is there any way to do such thing in MATLAB? Thank you, in advance, for your time!

0 Kommentare
Antworten (1)
Nipun
am 31 Mai 2024
Hi Rafegh,
I understand that you want to fit a specific level (0.5) of a contour plot to your data (shown in yellow and blue dots) and find the optimal set of input variables for a function with 6 input variables. Here's a way to do it in MATLAB:
Here's an example code:
% Example function with 6 input variables
myFunction = @(x1, x2, x3, x4, x5, x6, X, Y) ... % define your function
% Objective function to minimize the difference to the 0.5 contour
objective = @(vars) sum((myFunction(vars(1), vars(2), vars(3), vars(4), vars(5), vars(6), X, Y) - 0.5).^2);
% Initial guess for the variables
initialGuess = [1, 1, 1, 1, 1, 1];
% Optimization options
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'interior-point');
% Run the optimization
optimalVars = fmincon(objective, initialGuess, [], [], [], [], [], [], [], options);
% Display the optimal variables
disp('Optimal variables:');
disp(optimalVars);
You can refer to the MathWorks documentation for more details on fmincon: https://www.mathworks.com/help/optim/ug/fmincon.html
Hope this helps.
Regards,
Nipun
0 Kommentare
Siehe auch
Kategorien
Mehr zu Least Squares finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!