Discrete equation with two unknown variables

[EDIT: 20110523 16:16 CDT - clarify - WDR]
Hi,
I am looking for a simple way to find out the solution for this equation:
y1 = a*x1/(1+b)*x1
y2 = a*x2/(1/b)*x2
a and b are unkown but x1, x2, y1, y2 are known. I need discrete solutions for this equation and not 1 and 0 as solution. How can I compute this in MatLab, I know it is rather simple by head, but I have been cracking my head over this for several days and never am sure of what I find is right.

1 comentario

Ruben Verkempynck
Ruben Verkempynck el 20 de Mayo de 2011
Guys,
I made a huge mistake the equation should be:
y1 = a*x1/(1+b)*x1
y2 = a*x2/(1+b)*x2

Iniciar sesión para comentar.

 Respuesta aceptada

Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
This can be rewritten as:
a*x1^2 - b*y1 = y1
a*x2^2 - b*y2 = y2
or in matrix form:
A * [a b]' = [y1 y2]'
where:
A = [x1^2 -y1; x2^2 -y2];
So:
x1 = 2;
x2 = 3.3;
y1 = 9;
y2 = 2.9;
A = [x1^2 -y1; x2^2 -y2];
RHS = [y1 y1]';
solution = A\RHS;
a = solution(1);
b = solution(2);
HTH,
Arnaud

12 comentarios

Andrei Bobrov
Andrei Bobrov el 20 de Mayo de 2011
Hi, Arnaud
little typo, need
a * x1 ^ 2 - b * y1 = y1
a * x2 ^ 2 - b * y2 = 0
Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
Oops, actually, it's more like:
a*x1^2 - b*y1 = y1
a*b*x2^2 = y2
so it's a non-linear system of equations and the matrix approach I suggested won't work. However, by substitution, you can get a second order polynomial in b and use roots:
b^2*y1 + y1 - y2*x1^2/x2^2 = 0
which doesn't require the optimization toolbox
Clemens
Clemens el 20 de Mayo de 2011
Just a note - if A got an eigenvalue equal 0 there is a subspace of solutions.
So you can construct solutions by picking values in this subspace.
I suppose by discrete solutions you mean integers. You can search for them in this subspace.
Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
Correction:
b^2*y1 + b*y1 - y2*x1^2/x2^2 = 0
Ruben Verkempynck
Ruben Verkempynck el 20 de Mayo de 2011
Guys,
I made a huge mistake the equation should be:
y1 = a*x1/(1+b)*x1
y2 = a*x2/(1+b)*x2
Is this possible to find unique solutions? I am actually trying to find an a and b, these are parameters for a function that are somewhere in literature, but I can't find them. y's and x's are calculated through this function. I could find all these y's and x's in a list. But not the a and b.
Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
Then, my answer above "solution = A\RHS" is correct.
Clemens
Clemens el 20 de Mayo de 2011
But it is only unique if det(A) is not 0.
Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
True
Ruben Verkempynck
Ruben Verkempynck el 23 de Mayo de 2011
OK, so this is what I did:
x1 = 17698;
x2 = 81516;
y1 = 37601;
y2 = 102743;
A = [x1 -y1; x2 -y2];
RHS = [y1*x1 y1*x1]';
solution = A\RHS;
a = solution(1)
b = solution(2)
a =
-3.4770e+04
b =
-3.4064e+04
>> det(A)
ans =
1.2467e+09
As you can see the det(a) is not zero, but my a and b are know negative.
Ruben Verkempynck
Ruben Verkempynck el 23 de Mayo de 2011
Again a mistake:
RHS = [y1*x1 y1*x1]'; should be
RHS = [y1*x1 y2*x2]';
Arnaud Miege
Arnaud Miege el 23 de Mayo de 2011
Your A and RHS are wrong:
A = [x1^2 -y1; x2^2 -y2];
RHS = [y1 y2]';
solution = A\RHS;
a = solution(1)
b = solution(2)
This gives a = 0 and b = 1:
>> a*x1^2 - b*y1
ans =
37601
>> y1
y1 =
37601
>> a*x2^2 - b*y2
ans =
102743
>> y2
y2 =
102743
>> det(A)
ans =
2.1767e+014
Arnaud Miege
Arnaud Miege el 23 de Mayo de 2011
Correction: b = -1

Iniciar sesión para comentar.

Más respuestas (2)

Oleg Komarov
Oleg Komarov el 20 de Mayo de 2011
x1 = 2;
x2 = 3.3;
y1 = 9;
y2 = 2.9;
f = @(ab) [ab(1)*x1/(1+ab(2))*x1 - y1
ab(1)*x2/(1/ab(2))*x2 - y2];
R = fsolve(f,[0 0]);

4 comentarios

Ruben Verkempynck
Ruben Verkempynck el 20 de Mayo de 2011
??? Undefined function or method 'fsolve' for input arguments of type 'function_handle'.
Error in ==> Beverton_Holt at 8
R = fsolve(f,[0 0]);
>>
The example doesn't work, do I need a certain toolbox for fsolve?
Oleg Komarov
Oleg Komarov el 20 de Mayo de 2011
yes, sorry. The optimization toolbox.
Arnaud Miege
Arnaud Miege el 20 de Mayo de 2011
fsolve is part of the Optimization Toolbox, see http://www.mathworks.com/help/releases/R2011a/toolbox/optim/ug/fsolve.html
Ruben Verkempynck
Ruben Verkempynck el 20 de Mayo de 2011
OK, thanks, I should get that toolbox.

Iniciar sesión para comentar.

Andrei Bobrov
Andrei Bobrov el 20 de Mayo de 2011
f1 = @(x,x1,x2,y1,y2)[y1-x(1)*x1.^2./(1+x(2));y2-x(1)*x2.^2/(1./x(2))];
x1 = 1;x2 = 2;y1=10;y2=15;
fsolve(@(x)f1(x,x1,x2,y1,y2),[10,10]);

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by