How to draw "non-function" graph: f(x) = g(y) - math

I want to know is there any fast way to draw a graph of a "non-function" curve. For example
x^2+3x = y^3-4y+1
I know for normal function, like y=x^2, we can iterate x and calculate y, then draw the points. But for non-function curve, it will take a lot of times to iterate x, then solve function of y (using Newton method or alike). So please suggest me the correct way to draw them.
Thanks & Regards.

I am afraid there is no "generic" way except for the method you describe yourself: iterate over one variable and solve for the other.
Complications
Note that you have to be careful to find all solutions, not just a solution. This is a major stumbling block in creating a working general algorithm.
Another stumbling block is the singularity points: when f'(x)=0, you will want to solve for y and, vice versa, when g'(y)=0, you will want to solve for x. What if both are 0 at the same time? You will need to do some paper-and-pencil analysis.
Special Cases
There are some problem-specific simplifications though.
In your specific case the equation for x is quadratic, so a well known simple closed formula exists. This means that iterating over y and solving for x is easier. (The equation for y is cubic, so a less well known and much more complicated formula exist too).
Another way is to find a parametric representation of your curve (e.g., x^2+y^2=1 is equivalent to x=cos(t); y=sin(t); 0<=t<2*pi).

Related

How can I determine that Y_n can be represented as a funtion of X_n

On enter I'm having a sequence of pairs (X_n, Y_n). Consider the following two graphics of two possible sequences.
in first case X_n can be modeled as f(Y_n) while in second case it obviously has no sense. The question is how can I determine if trying to represent X_n as f(Y_n) makes sense? Probable there is some criterium or something like that?
What can be done in multivariate situation (i.e. when we're trying to represent Y as f(X_1, X_2, ..., X_k))?
Please note that trying to fit points with something graphicaly (e.g. like on first graph) and seeing if it fits the data is not OK. I'm looking for numerical criterium.
Please feel free to propose variants in either matlab or R. A link on page with algorithm will be great too!

Lagrange polynomial: Unexpected interpolation results

I am trying to interpolate a series of data points using 2nd lagrange polinomial.
having
point1:(5;100)
point2: (9;17)
point3: (12;17)
and the formula
y=(x-x2)*(x-x3)/(x1-x2)*(x1-x3)*y1+
(x-x1)*(x-x3)/(x2-x1)*(x2-x3)*y2+
(x-x1)*(x-x2)/(x3-x1)*(x3-x2)*y3
It is obvious that a quadratic function might not fit the data.. It is just an example.
But i wonder why the value is surprisingly high for x=7.
If i am not wrong its y=1500.
Is the above formula correct?
answer:
In summary:
For the same x, you can't have two different y values; this violates the definition of a function.
you are missing brackets in your formula! Not (x-x2)*(x-x3)/(x1-x2)*(x1-x3), but ((x-x2)*(x-x3)) / ((x1-x2)*(x1-x3)).
back to 1>, note that the interpolation formula has x3-x2 in the denominator. If you have tied values, you will be dividing 0.
How can you make interpolation on such small data set? Yet you are asking for a quadratic interpolation!
follow-up:
1) fixed it. Accidentally i switched all the x and y values. So the points were in format (y,x).
Ah, haha, no wonder.
2) Thank you! The brackets improved the approximation. Regarding the missing brackets: I got the formula from the accepted answer here: Best way to find Quadratic Regression Curve in Java, but I don't understand this rule.
This is the famous, yet fundamental interpolation: Lagrange interpolation. You can verify its formula at Wolfram mathworld: Lagrange Interpolating Polynomial. I don't give you wikipedia link because this one looks more beautiful.
The link you found must contain a typo. Since you have suggest an edit to fix that, hopefully it will soon get approved.
3) It is a (significant larger (which answers your 4th question) time series. So it is impossible to have tied values.
Yes, time series won't have tied values.
formula should be correct.but when x=17,you have two different y value,it's might the cause of the trouble.you can try change anthor x.

How can I do blind fitting on a list of x, y value pairs if I don't know the form of f(x) = y?

If I have a function f(x) = y that I don't know the form of, and if I have a long list of x and y value pairs (potentially thousands of them), is there a program/package/library that will generate potential forms of f(x)?
Obviously there's a lot of ambiguity to the possible forms of any f(x), so something that produces many non-trivial unique answers (in reduced terms) would be ideal, but something that could produce at least one answer would also be good.
If x and y are derived from observational data (i.e. experimental results), are there programs that can create approximate forms of f(x)? On the other hand, if you know beforehand that there is a completely deterministic relationship between x and y (as in the input and output of a pseudo random number generator) are there programs than can create exact forms of f(x)?
Soooo, I found the answer to my own question. Cornell has released a piece of software for doing exactly this kind of blind fitting called Eureqa. It has to be one of the most polished pieces of software that I've ever seen come out of an academic lab. It's seriously pretty nifty. Check it out:
It's even got turnkey integration with Amazon's ec2 clusters, so you can offload some of the heavy computational lifting from your local computer onto the cloud at the push of a button for a very reasonable fee.
I think that I'm going to have to learn more about GUI programming so that I can steal its interface.
(This is more of a numerical methods question.) If there is some kind of observable pattern (you can kinda see the function), then yes, there are several ways you can approximate the original function, but they'll be just that, approximations.
What you want to do is called interpolation. Two very simple (and not very good) methods are Newton's method and Laplace's method of interpolation. They both work on the same principle but they are implemented differently (Laplace's is iterative, Newton's is recursive, for one).
If there's not much going on between any two of your data points (ie, the actual function doesn't have any "bumps" whose "peaks" are not represented by one of your data points), then the spline method of interpolation is one of the best choices you can make. It's a bit harder to implement, but it produces nice results.
Edit: Sometimes, depending on your specific problem, these methods above might be overkill. Sometimes, you'll find that linear interpolation (where you just connect points with straight lines) is a perfectly good solution to your problem.
It depends.
If you're using data acquired from the real-world, then statistical regression techniques can provide you with some tools to evaluate the best fit; if you have several hypothesis for the form of the function, you can use statistical regression to discover the "best" fit, though you may need to be careful about over-fitting a curve -- sometimes the best fit (highest correlation) for a specific dataset completely fails to work for future observations.
If, on the other hand, the data was generated something synthetically (say, you know they were generated by a polynomial), then you can use polynomial curve fitting methods that will give you the exact answer you need.
Yes, there are such things.
If you plot the values and see that there's some functional relationship that makes sense, you can use least squares fitting to calculate the parameter values that minimize the error.
If you don't know what the function should look like, you can use simple spline or interpolation schemes.
You can also use software to guess what the function should be. Maybe something like Maxima can help.
Wolfram Alpha can help you guess:
http://blog.wolframalpha.com/2011/05/17/plotting-functions-and-graphs-in-wolframalpha/
Polynomial Interpolation is the way to go if you have a totally random set
http://en.wikipedia.org/wiki/Polynomial_interpolation
If your set is nearly linear, then regression will give you a good approximation.
Creating exact form from the X's and Y's is mostly impossible.
Notice that what you are trying to achieve is at the heart of many Machine Learning algorithm and therefor you might find what you are looking for on some specialized libraries.
A list of x/y values N items long can always be generated by an degree-N polynomial (assuming no x values are the same). See this article for more details:
http://en.wikipedia.org/wiki/Polynomial_interpolation
Some lists may also match other function types, such as exponential, sinusoidal, and many others. It is impossible to find the 'simplest' matching function, but the best you can do is go through a list of common ones like exponential, sinusoidal, etc. and if none of them match, interpolate the polynomial.
I'm not aware of any software that can do this for you, though.

Looking for interesting formula

I'm creating a game where players can make an alloy. To make it less predictable and more interesting, I thought that the durability and hardness of an alloy should not be calculated by a simple formula, because it will be extremely easy to find extrema, where alloy have best statistics.
So the questions is, is there any formula for a function where extrema can be found only by investigating all points? Input values will be in percents: 0.0%-100.0%. I think it should look like this: half sound wave
A very simple way would be a couple of sin function, just vary the constants and the sign for each new player. Here is one example (sin(1.1*x) + sin(x) + sin(0.9 *x))^2
If you use this between 10pi and 20pi you have an by average increasing function with local minima.
Modulating a simple linear or exponential function with trigonometric functions whose frequency and amplitude are dependent on the input should get you what you want.
You don't need a formula, I think — throw a bunch of random values around your domain, and then interpolate (linear interpolation will do) between them. Then you can even change the "formula" completely each time the game is run, or once in a while, or change it slowly with time, etc, etc.
If you want something that is very hard to predict then I would suggest involving a random number generator with the same seed every time. You can use it as an envelope for whatever function you come up with (trig functions or what not) to make it more jagged.
An interesting formula to use would be that of gamma of the Black-Scholes options pricing model. It goes as follows:
You can easily replace the variables, here's a graph of how the function looks:
alt text http://www.sqbimmer.com/aalex/gamma.png

Calculus, How can you find an equation from a series of numbers?

I'm analyzing financial data and would like to find the inflection points of a line. I know I can do this using derivatives, but first I need an equation. Is there a way to generate an equation based off of a series of numbers. I would need to do this programmaticly.
Spline interpolation is probably more useful for you than polynomial interpolation: if you fit a polynomial, it must inevitably head off to +/- infinity outside your data range.
You will also want a method which allows a slightly loose fit: financial data is often a bit noisy which can result in very weird curves if you try to fit it exactly.
There are established procedures for turning a set of existing data points into a polynomial; this is called Polynomial Interpolation. This article in Wikipedia: http://en.wikipedia.org/wiki/Polynomial_interpolation
explains it mathematically. You can probably Google for algorithms easily enough.
Given enough points, your polynomial tracks the original, unknown function reasonably well, so the polynomial's inflection points should roughly coincide with the peaks and troughs of your data.
On the other hand, we all know there's not really a function behind financial data. So if I were you I'd scan along those points and find every point that has a smaller value to either side of it, and declare that a high; and vice versa for lows. Force-fitting this data into a fictitious function isn't going to make it any more useful.
Update: Tom Smith advises that spline interpolation is to be preferred to polynomial interpolation for this kind of thing, and Wikipedia bears him out. Or rather, it's bullish on his answer.
What you are thinking is analytical calculus ... when having discrete data (e.g. points), you have to do it numerically. Now, a line usually doesn't have inflection points, so I guess you're thinking of a curve. You can either interpolate some kind of it through the points, then calculate the first derivative (also numerically, but for a larger number of points), or you can just calculate the first derivation from the points you have (which will be better depends on how many points you actually have).
But really, this is just theory since we don't know the nature of data, or the language or anything.
For more on the subject search: numerical analysis on wiki, and go from there.
I think curve fitting might help you in this case. Here is a discussion which might be handy.
cheers

Resources