I am trying to come up with a simple equation that fits a curve.?
-
My goal is to have an equation that helps me graph some user settings that someone is putting into my program (for work, not a school project!) I am writing a computer program, and prompting the user for 3 values. Call them T, R, and P. By default, T=20, R=6, and P=0. Without getting too detailed, P represents a curvature, and with P=0, the graph is a straight line, connecting two points. In the default case, it connects (x,y) points of (0,10) and (20,6) with a straight line. More generally, the curve will always connect points (0,10), with point (T,R). But in the default case, this is a small diagonal segment running from (0,10) to (20,6). The curvature parameter, P, will determine how far off that "default diagonal" the curve ends up being. For example, for positive values of P, the curve will be above and to the right of that "default diagonal" (sort of a frown shape), while with negative values of P, it will be below and the left of the default diagonal (sort of a smile or a cup shape.) In all cases, the curve should go through the points (0,10) and (T,R). In no case for x values between 0 and T will the y value be bigger than 10 or less than R. I don't care what the curve does with values of x less than zero or greater than T. I just want a simple equation. Any idea how I calculate this? Thanks folks. That's your math stumper for the day!
-
Answer:
The boneheaded way to do this is to use circles passing through (0,10) and (T,R), and letting P = the maximum gap between the arc and the line {(0,10), (T,R)}. But the resulting equations are extraordinarily messy. If you're still interested, leave this one open and maybe I'll get it back to you. At least with this approach, you will get perfect circular arcs with uniform curvature. Edit: Here's my version of a parabolic equation that passes through points (0,10) and (T,R), where P controls the curvature. -Px² + (PT + R/T - 10/T)x + 10 The link gives the graphs for P = 0.01 and -0.01, while the straight line is {(0,10), (T,R)}, where T = 20 and R = 6, as given. If you are writing programs to draw curves which don't have to have a particular mathematical expression, look up Bezier Curves. See wiki. This is a simple and powerful way to draw curves, widely used in the computer graphics industry. For example, for a Bezier starting at (0,10) and ending at (20,6), with a control point at, say, (10, 8+P), we can plot out the parametric curve: x = (0)t² + (10)2t(1-t) + (20)(1-t)² y = (10)t² + (8+P)2t(1-t) + (6)(1-t)² P becomes the vertical displacement of the curve from the line at midpoint. When P = 0, you get a straight line. For positive P, you get a hump from (0,10) to (20,6). For negative P, you get a bowl from (0,10) to (20,6). When you are plotting graphics by program, it's more efficient to use parametric curves of the form (x(t), y(t)). There is little or no value in using curves of the form (x, y(x)). Edit 2: To compare the quality of Bezier curves with the parabolic version given above, check the 2nd graphic in the link provided. All three lines, including the straight line, are Beziers, using the same equation described above, where P = 2, 0, -2. Edit 3: Yeah, you're getting the hang of this now, nan seat. t runs from 0 to 1, I always think of it as a generic knob to twirl, moving the point (x(t), y(t)) back and forth with it. There are higher order Beziers, but notice that they can be expressed as binomial expansions of (t + (1-t))^n, except that in addition to the binomial factors, we have "weighting coefficients", which are the coordinates of the control points. I think you'll get this. For example, x1 t^3 + x2 3 t^2(1-t) + x3 3 t(1-t)^2 + x4 t^3, etc. And thank you, both Falzoon and Ben, for your analysis and comments.
nan_seat at Yahoo! Answers Visit the source
Other answers
What a great challenge. I love it, but I'm about to get some kip, so I'll try and add some more tomorrow. Just as a preliminary, I've found a cubic equation that satisfies the "frown" shape only, although it's mirror image about the straight line should be all that's required. No doubt there will be some restrictions on P, but I'll try and work those out later. The equation is : y = ax^3 + bx^2 + 10, where, a = (10P^2 - 10T^2 - RP^2) / [P^2T^2(P - T)] and b = (RP^3 + 10T^3 - 10P^3) / [P^2T^2(P - T)] EDIT: As with Ben and Scythian1950, I did consider trigonometric curves and the very simple circle, but I opted for a polynomial because of the ease of differentiating. As Ben stated, a quadratic won't cut it, so I used the next best thing, a cubic. The cubic above does work between all your restrictions, but as I said I would, I have now calculated the restriction on P. It is that P > T[10/(10 - R)]^(1/3). (I set up the equation so that P will always be one of the positive roots of y.) Note that the curve always intersects (0, 10) and (T, R). Changing P changes the curvature. Example 1: P = 28, T = 20, R = 6 http://www.wolframalpha.com/input/?i=plot+a*x%5e3%2bb*x%5e2%2b10+where+a%3d(10*28%5e2-10*20%5e2-6*28%5e2)%2f(28%5e2*20%5e2*(28-20))%2c+b%3d(6*28%5e3%2b10*20%5e3-10*28%5e3)%2f(28%5e2*20%5e2*(28-20))&incParTime=true Example 2: P = 50, T = 20, R = 6 http://www.wolframalpha.com/input/?i=plot+a*x%5e3%2bb*x%5e2%2b10+where+a%3d(10*50%5e2-10*20%5e2-6*50%5e2)%2f(50%5e2*20%5e2*(50-20))%2c+b%3d(6*50%5e3%2b10*20%5e3-10*50%5e3)%2f(50%5e2*20%5e2*(50-20))&incParTime=true Hopefully, I'll get back with the other half of the problem. EDIT2: I've just seen Scythian's beautiful work, so as mine is not going too well, I'd prefer to desist bashing my head against a brick wall and just give him a TU. EDIT3: Thanks to other answerers for allowing me to see that a quadratic can work. Sometimes I just (enjoyably) muddle through things I've never done before, or don't understand very well, so I'm in awe at learning from such knowledgeable people.
falzoon
Of course there are many ways to do this. If we want to stick with a quadratic function (y=ax^2+bx+c), then everything is straightforward until we get to your last restriction that the y-values be bounded between 10 and R for x between 0 and T. This essentially puts a bound on the concavity (second derivative), so taking a=P won't work. A solution that is simple for the program but potentially ugly would be to only allow certain values of P as input. Unfortunately these restrictions would have to depend on T,R... A more elegant solution (IMO) is to make a transformation. Take a= [2(R-10) / (pi T^2) ] * arctan P. Since arctan is bounded between +/- pi/2, this a is bounded between +/- (R-10)/T^2. This is essentially what we need to achieve your last condition. We of course need c=10 for the curve to pass through (0,10). And to pass through (T,R) requires that b = (R-10-aT^2)/T. In case you're interested in the derivation of what's above: I started solving for c and b, in terms of a. Now to keep our y-values bounded appropriately, it's enough to bound the a-values so that at the extremes, the derivative at 0 and at T are zero (so the parabola has its vertex at the endpoints in the extreme, or outside of the range (0,T) in the intermediate). Taking the derivative and evaluating at 0 and T gives (R-10 +/- aT^2) / T and finding where each of these is zero gives the appropriate extreme values of a. Now we need some way of taking P and producing some value of a in this range, and the arctangent was the first thing to pop to mind. Hopefully that works. The major downside in my eyes would be the requirement to calculate an arctangent of P. It might be interesting to also try an exponential function or the like. EDIT: While working out the formulas above, I hadn't really thought of the value of a as relating to the position of the vertex of the parabola, but it leads to an interesting remark. At the extremal values of a the vertex is at x=0 and x=T, and between those values the vertex is OUTSIDE of that range. So at some point it "goes through infinity", and of course this occurs when our curve is the straight line. Mildly amusing IMO. In response to additions from the other posters, first note that a quadratic DOES work, you just can't take an unlimited range of values of a. (But of course you need to also limit the coefficients of the cubic.) I hadn't thought of circular arcs, but I like the idea. Note that here too you would need to limit the parameter Scythian suggests to fulfill the asker's final condition (you could do a similar arctangent trick as I've done). Finally, I must defer to Scythian's greater knowledge on applications. It does seem likely that a parametric (x(t), y(t)) would be easier to deal with, and Bezier curves are something I recognize (largely) in name only.
Ben
Related Q & A:
- I'm trying to write a song?Best solution by Yahoo! Answers
- I was thinking of buying a web cam, but I was woundering if you can use a digital camera instead of a web cam.Best solution by Yahoo! Answers
- I'm trying to get a meeting with a diplomat to counsel me on a career in international affairs?Best solution by Yahoo! Answers
- I am trying to open up a daycare.Best solution by Yahoo! Answers
- I was trying to send a e-mail and it did not send how can i find it again.Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.