Hi,
Yes, there is a way to calculate all possible combinations of x1 and x2 that lead to a certain value for y, given x3.
Here's a MATLAB code example that demonstrates how to do this:
load my_regression_model.mat;
x1_range = linspace(0, 10, 100);
x2_range = linspace(0, 10, 100);
[x1_grid, x2_grid] = meshgrid(x1_range, x2_range);
x1_vec = reshape(x1_grid, [], 1);
x2_vec = reshape(x2_grid, [], 1);
X = [x1_vec, x2_vec, repmat(x3, numel(x1_vec), 1)];
y_pred = predict(my_regression_model, X);
idx = find(abs(y_pred - y_desired) < 0.01);
x1_desired = x1_vec(idx);
x2_desired = x2_vec(idx);
In this code example, we first load the regression model (my_regression_model) that was created using the Regression Learner toolbox. We then specify the desired value for y (y_desired) and the value of x3 (x3).
Next, we define a range of values for x1 and x2 (x1_range and x2_range) and use meshgrid to create a grid of all possible combinations of x1 and x2. We reshape the grid into a vector for prediction and create a matrix of the input variables (X).
We then use the predict function to predict y for each combination of x1 and x2. We find the indices of the combinations that lead to the desired value of y (idx) and extract the corresponding values of x1 and x2 (x1_desired and x2_desired).
Note that in the find function, we use a tolerance of 0.01 to account for small differences between the predicted values and the desired value of y. You may need to adjust this tolerance depending on the precision of your regression model and the desired level of accuracy.
Hope it helps!!