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

조회 수: 15 (최근 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