- 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
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/518837/image.jpeg)
0 comentarios
Respuestas (1)
Nipun
el 31 de Mayo de 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 comentarios
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!