Clear Filters
Clear Filters

Fitting specific level of contour plot to data

1 view (last 30 days)
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!

Answers (1)

Nipun
Nipun on 31 May 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:
  1. Define your function.
  2. Create a function to calculate the difference between your data and the 0.5 contour level.
  3. Use fmincon to minimize this difference and find the optimal input variables.
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

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!