Re: solution to nonlinear eq
- From: "Roger Stafford" <ellieandrogerxyzzy@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Jul 2008 18:07:10 +0000 (UTC)
"Andrew Palmer" <apalmer28@xxxxxxxxxxxxxx> wrote in message <g6c35q
$mi1$1@xxxxxxxxxxxxxxxxxx>...
Given an equation of the form:
A = b(1+b) + g(1+g)
where; A, b and g are restricted to integers
A is known, b and g are unknown
What is the best method to determine the possible values
for b and g?
Thanks,
The following finds all possible non-negative integer solutions. (Any
negative solutions can be determined from these in a trivial manner.) I have
not been able to think of any more efficient method.
function [B,G] = andrew(A)
b = []; g = [];
a = A/2;
if round(a)~=a | A<0, return, end
for b = 0:floor((sqrt(1+4*a)-1)/2)
a = a-b;
g = (sqrt(1+8*a)-1)/2;
if round(g)==g
B = [B;b]; G = [G;g];
end
end
return
Arrays B and G will have all possible non-negative b and g solution pairs, if
any, (other than reversing their order.)
I have assumed here that the 'sqrt' function gives an exact answer for the
square root of any integer squared. Otherwise the two 'sqrt' calls above
would have to be amended to allow a small tolerance for rounding errors.
Roger Stafford
.
- Follow-Ups:
- Re: solution to nonlinear eq
- From: John D'Errico
- Re: solution to nonlinear eq
- References:
- solution to nonlinear eq
- From: Andrew Palmer
- solution to nonlinear eq
- Prev by Date: Re: .ike files
- Next by Date: Re: Fourier Transform?? -- Data Analysis
- Previous by thread: solution to nonlinear eq
- Next by thread: Re: solution to nonlinear eq
- Index(es):
Relevant Pages
|