RE: Corresponding function to given values...
- To: mathgroup at smc.vnet.net
- Subject: [mg35973] RE: [mg35966] Corresponding function to given values...
- From: "DrBob" <majort at cox-internet.com>
- Date: Sun, 11 Aug 2002 05:13:31 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Here's a start: pairs = {{1, 1}, {2, 4}, {3, 9},{4,16}} ClearAll[f, g] g[{a_, b_}] := (f[a] = b) g /@ pairs ?? f That defines f only at the points in your list of ordered pairs. If you want to identify a polynomial (or other) fit, you could use Fit, if you have in mind what the functional form might be. Unfortunately, it might not do what you expect! You can also use Interpolation to define f on the range of values you have. expr1 = Fit[pairs, {1, x}, x] expr3 = Fit[pairs, {1, x, x^2}, x] expr4 = Fit[pairs, {1, x, x^2, x^3}, x] expr5 = Fit[pairs, {1, x, x^2, x^3, x^4}, x] expr6 = Interpolation[pairs] Plot[Evaluate[# - x^2], {x, 1, 3}] & /@ {expr1, expr2, expr3, expr4, expr5, expr6[x]}; Bobby Treat -----Original Message----- From: Sven Richter [mailto:Sven.Richter at unibw-muenchen.de] To: mathgroup at smc.vnet.net Subject: [mg35973] [mg35966] Corresponding function to given values... Is there a possibility that Mathematica gives me a function to given pairs of values? In other words: I have several pairs like {1, 2}, {2, 4}, {3, 9}. And I what like to know the corresponding function (what is in this example obviously f[x]=x^2). TIA Sven