z=f(x,y) and w=f(x,y). I am trying to reverse the table to get x=f(z,w) and y=f(z,w).

9 views (last 30 days)
Hello,
I have a 2 lookup tables with same X and Y but the outputs are Z and W. Basicaly I have a z=f(x,y) and w=f(x,y). I am trying to reverse the table to get x=f(z,w) and y=f(z,w). what is the best way of doing that in Matlab. the table data is in this format:
  5 Comments
Torsten
Torsten on 7 Mar 2023
Edited: Torsten on 7 Mar 2023
FluxQ=Iq x Lq(inductance) FlusD= FluxPM + Id x Lq
If you have equations z = f1(x,y) and w = f2(x,y), why don't you solve for x and y given z and w ?
Two equations in two unknowns.

Sign in to comment.

Answers (2)

John D'Errico
John D'Errico on 9 Mar 2023
In general, this is often impossible. That is so for good reasons too.
The problem is, IF you have any instances where the responses would not be a single valued function, then it would fail. For example:
syms x y
z = x.^2 + y.^2;
fsurf(z)
For any value of z and x, you can find two values of y. So the coutours of z here are circles in the (x,y) plane, and so there is no unique way to invert this function in a table.
But we can look at your problem. Does that data suffer from any issues that would cause failure? Some contour plots will help us there.
A=[17.9 18.0 18.1 18.2]';
B=[0.4 0.5 0.6 0.7];
C=[67 89 95 108
74 92 110 123
80 97 115 127
84 106 119 135];
D=[40 65 80 95
50 72 85 103
60 93 97 110
70 100 103 127];
contour(A,B,C)
contour(A,B,D)
So there are no overtly problematic contours that I see. There are no circular contours. There are no places where a contour is u-shaped. So does that mean a solution MUST exist? There are still problems.
We can use these contour plots to understand what is happening. I've picked out two contour levels that will be problematic for you.
contour(A,B,D,[80 80],'r')
hold on
contour(A,B,C,[100 100],'b')
hold off
legend('D == 80','C == 100')
grid on
Do you see what I did? The contour plot of D==80 and that of C==100, cross at TWO distinct points in the (A,B) plane. And that means there is no inverse for your problem. You CANNOT use a scattered interpolant here. There is no unique solution.
  2 Comments
Sobhi Zeidan
Sobhi Zeidan on 9 Mar 2023
Thank you for the response. Assuming the Data has a one to one correspondence , How do i get what I am looking for? This is random data that I put together. the equation is a linear equation and should have a one to one correspondence .
Torsten
Torsten on 9 Mar 2023
Edited: Torsten on 9 Mar 2023
the equation is a linear equation and should have a one to one correspondence .
As noted above, if you have equations, you can solve for the unknowns.
syms x y z w
eqn1 = z == 3*x+5*y+7;
eqn2 = w == -4*x+8*y-12;
solve([eqn1 eqn2],[x y])
ans = struct with fields:
x: (2*z)/11 - (5*w)/44 - 29/11 y: (3*w)/44 + z/11 + 2/11

Sign in to comment.


Star Strider
Star Strider on 7 Mar 2023
Apparently, X, Y, Z and W are all equal-sized matrices. Assuming that there is essentially a one-to-one correspondence between the matrices, it could be possible to do this with the scatteredInterpolant function. Everything essentially depends on the functions that create Z and W.
  6 Comments
Sobhi Zeidan
Sobhi Zeidan on 9 Mar 2023
So after trying to understand how the data moves around with interp1 and interp2, I came up with this code. I am stuck at the final step of the code. I am trying to get the data in the format of X=f(z,w) and Y=f(z,w).
%%%%%%%%%%%%%%%%%%%
% --------------
% A-----> | |
% | |
% | |-----> C
% B-----> | |
% --------------
%
% --------------
% A-----> | |
% | |
% | |-----> D
% B-----> | |
% --------------
A=[17.9 18.0 18.1 18.2]';
B=[0.4 0.5 0.6 0.7];
C=[67 89 95 108
74 92 110 123
80 97 115 127
84 106 119 135];
D=[40 65 80 95
50 72 85 103
60 93 97 110
70 100 103 127];
%Min and Max of C data
C_Data = 67:4:135;
%Min and Max of D data
D_Data = 40:4:127;
%These for loops will get Data for
%%%%%%%%%%%%%%%%%%%
% --------------
% C-----> | |
% | |
% | |-----> A
% B-----> | |
% --------------
%
% --------------
% A-----> | |
% | |
% | |-----> B
% D-----> | |
% --------------
for i=1:length(B)
for j=1:length(C_Data)
%table Data for B column at given index. This gives the value of C
%for the specific B column
B_Data=interp2(A,B,C',A,B(1));
%get the value of A for the given B and C value
A_Data(j,i)=interp1(B_Data,A,C_Data(j),'linear','extrap');
end
end
A_Output=A_Data;
for i=1:length(A)
for j=1:length(D_Data)
%table Data for Row A at given index. This gives the value of D
%for the specific Row A
A_Data=interp2(A,B,C',A(i),B);
%get the value of B for the given A and D value
B_Data(i,j)=interp1(A_Data,B,D_Data(j),'linear','extrap');
end
end
B_Output=B_Data;
%How Can I get this Data
%%%%%%%%%%%%%%%%%%%
% --------------
% C-----> | |
% | |
% | |-----> A
% D-----> | |
% --------------
%
% --------------
% C-----> | |
% | |
% | |-----> B
% D-----> | |
%

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!