MATLAB: Obtain x and y variables for a given value of z which is a function of both

extrapolationinterpolationmatrixmesh

Hello all, thanks for looking.
For example if I have composite material consisting of concentrations of A and B and their resulting measured stress value is Z (in picture below this is the matrix in green). Now given the value of z, how do I find the value of A and B which correspond to it?
Usually the interp2 would work if I know A and B and want to find Z value, but now I want to do the opposite. The z value is beyond the range of results too, so may need to be extrapolated.
I currently have the script below whcih plots a surface sketch but I want to essentially find x and y values that correspond to a specific z value. I assigned the A concentration as x, B concentration as y and the stress value of thir combination z.
So as an exmaple, I want to know x and y values that would make z=0.4.
Many thanks for your help!
x=[2.5; 5]
y=[1; 1.5]
z=[4.9 5.3; 13.8 14.4]
surf(x,y,z)

Best Answer

As mentioned in the comment to your other question, if you try to extrapolate the surface that there is not a unique solution corresponding to a given z value. The following shows one of the ways; however, you can note that the solution is different every time you run it. It is because each initial guess to fsolve() will lead to a different solution.
x=[2.5; 5];
y=[1; 1.5];
z=[4.9 5.3; 13.8 14.4];
[X,Y] = meshgrid(x,y);
mdl = scatteredInterpolant(X(:), Y(:), z(:));
fun = @(x) mdl(x(1),x(2));
sol = fsolve(@(x) fun(x)-0.4, rand(1,2));
x_sol = sol(1);
y_sol = sol(2);