• Status: Solved
• Priority: Medium
• Security: Public
• Views: 1359

# c# code to solve horizontal parabola, y as func of x=1,2,3,4.., given 3 points, incl. x=0,y=0

For a parabola X = A Y * Y + B Y
This is horizontal parabola passing through x=0,y=0
The c#  DotNet 2.0 function should look like
ArrayList yList getNsuccessiveYvalues (int x1, int y1, int x2, int y2, int x3, int y3, yListSize)
{
}
It gets 3 points x1,y1,x2,y2,x3,y3 and also a number representing how many Y values should be calculated, for X=1,2,3,4 ...
That is for X starting at 1 in steps of 1.
Actually x1,y1 are 0,0 in my case, though it would be nice if the function could be more general :-).
The returned Y values I need them to be of int type, so the double results should be rounded to the close integers.

an example of actual parameters is: x1=0,y1=0,x2=1,y2=6,x3=20,y3=60,yListSize=50

I want also to show the results as a graph in .NET 2.0 WinForm by GDI.

I would appreciate a solution.
0
michael-lev
• 3
• 2
• 2
1 Solution

Commented:
For starters:
• X = A Y * Y + B Y is only guaranteed to pass through (0,0) if B = 0.
• Are you guaranteed that all 3 points provided will fit such a parabola?  Will you throw an exception if they do not?
If you know the origin is at (0,0), then the only variable for which you need to solve is A:

Using (x1,y1) to do so:
A = (X / (Y*Y));

Then you would loop from 0 to yListSize or -yListSize depending on whether A is positive or negative.  Knowing Y for the values you're plugging in, you would solve for X.  The resulting pairs are what you place into the list you will return.

Questions?
0

Author Commented:
To DanielWilson:

1. x=a*y*y + b*y  passes through 0,0  also fo b != 0
What you wrote does not make sense to me. Maybe you were too fast...

Anyway, if you solve my question more generally, i.e. also for 1st point other than 0,0
then of course the horizontal parabola full equation is X=A*Y*Y + B*Y + C

2. Pay attention that in this equation, after the program evaluates A and B,
the intuitive solution is to evaluate X as a function of Y, by x=a*y*y + b*y
But I need to put in the list y values for x = 1, 2, 3, etc.

So I suspect this is not trivial...
0

Commented:
X = A Y * Y + B Y
x1 == A * y1 * y1 + B * y1
x2 == A * y2 * y2 + B * y2
x1*y2 == A * y1 * y1 * y2 + B * y1 * y2
x2*y1 == A * y2 * y2 * y1 + B * y2 * y1
x1*y2 - x2*y1 == A * (y1 * y1 * y2 -  y2 * y2 * y1 ) + B * (y1 * y2 -  y2 * y1)
A = (x1*y2 - x2*y1) / (y1 * y1 * y2 -  y2 * y2 * y1)
B = (x1 -  A * y1 * y1) / y1
0

Commented:
1.  Yeah, I wasn't thinking right.

Will think some more ... unless ozo beats me to it :)
0

Author Commented:
to Ozo:

finding A,B is only first step. :-)
It enables evaluating X as a function of Y, by x=a*y*y + b*y
But I need to evaluate Y values for series of X values (for X=1, 2, 3, 4, etc)

So indeed I am still wondering what is the effective\efficient way for doing this?
0

Commented:
x=a*y*y + b*y
a*y*y + b*y - x = 0
y = (-b ± sqrt(b² - 4ax))/2a
0

Commented:
sorry
y = (-b ± sqrt(b² + 4ax))/2a
0

## Featured Post

• 3
• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.