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

8 次查看(过去 30 天)
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)
  2 个评论
Stephen23
Stephen23 2020-5-22
"Now given the value of z, how do I find the value of A and B which correspond to it? "
Even if your surface is nicely continuous there can be zero, one, some finite number, or infinite solutions to this. Consider your example data, for example if we look for values where z=10 then this means all x and y values on the line from (2.5,1.2865) to (5,1.2582), i.e. infinite points. Which of those infinite points do you want as the output?
Zhenteng Shen
Zhenteng Shen 2020-5-22
I see, I completely understand what you are saying now, Ameer demonstrated it graphically for me in my other question. Thank you for taking your time to comment.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-22
编辑:Ameer Hamza 2020-5-22
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);
  5 个评论
Zhenteng Shen
Zhenteng Shen 2020-5-22
Hi Ameer, just an update I have found out which starting points to use in place of rand(1,2) for fsolve so will create a 1x2 matrix of the starting x value and y value to use. In this case your answer is exactly what I was looking for!!! I can't believe it, THANK YOU SO MUCH AGAIN!!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by