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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/298163/image.png)
2 个评论
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?
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!