# Thread: MATHEMATICA FindFit experimental data

1. ## MATHEMATICA FindFit experimental data

Hi everyone,
I want use FindFit for Data witch i read from a file, but i can't do it, please help me to solve this problem.
i do this:

voltage = data[[All, 1]];
current = data[[All, 2]];
FindFit[data,a*x + b*y + c*x*y + e*x^2 + e*y^2, {a, b, c, e, d}, {x, y}];

FindFit::fitc: Number of coordinates (1) is not equal to the number of variables (2).

help me if you can please

2. That error means your list of data is not a list of {x,y,z} values like:

mydata = {{1, 1, 1}, {2, 2, 3}, {3, 3, 3}, {4, 4, 3}};

FindFit[mydata,
a*x + b*y + c*x*y + e*x^2 + e*y^2, {a, b, c, e, d}, {x, y}]

First make sure your data is in the correct format: Test the code first with an explicit definition of the data like I did above. Then get the file reading part to read in the data as the explicit format you now know works. If you want to fit {x,y} pairs in the form of a function y=f(x), then you'll have to specify the expression for the function and just one variable {x}. There are however other functions that may suit your need like Fit, Interpolating Function, etc. Check the help.

3. thanks, but i have to use a function of 2 variables
D(V,I )=a*I+b*V+c*I*V+d*I^2+e*V^2;
for fiting data I=f(V), i don't have z
mydata:
V I
0.047790 9.01875E-6
0.070060 1.40463E-5
0.082600 1.6855E-5
0.089750 1.88125E-5
0.108330 2.28212E-5
0.119740 2.56288E-5
0.132350 2.97075E-5
0.153210 3.39375E-5
0.157250 3.668E-5
0.168920 3.91425E-5
0.196460 4.713E-5
0.206590 5.09363E-5
0.230800 5.8345E-5
0.236900 6.17413E-5
0.244330 6.4705E-5
0.251710 6.73688E-5
0.278770 7.55775E-5
0.295320 8.209E-5
0.300400 8.308E-5
0.319740 9.21838E-5
0.322990 9.53775E-5
0.353020 1.0984E-4
0.360520 1.1125E-4
0.367660 1.17813E-4
0.388450 1.2791E-4
0.401650 1.35332E-4
0.418820 1.5154E-4
0.424540 1.55591E-4
0.438110 1.58598E-4
0.463590 1.92103E-4
0.477580 2.02443E-4
0.483600 2.05795E-4
0.489890 2.10896E-4
0.520780 2.36406E-4
0.529070 2.43365E-4
what i do

4. Then is $D(I,v)$ equal to some constant? For example, suppose I have the relationship:

$k=aI+bV+cIV+dI^2+eV^2$

and I want to find the parameters $\{a,b,c,d,e\}$ so that when I solve that equation for $I=f(V)$, the resulting function fits the data sets. Then I'd use Solve:

Code:
In[20]:=
Solve[k == a*i + b*v + c*i*v + d*i^2 +
e*v^2, i]

Out[20]=
{{i -> (-a - c*v + Sqrt[(-a - c*v)^2 +
4*d*(k - b*v - e*v^2)])/(2*d)},
{i -> -((a + c*v + Sqrt[(-a - c*v)^2 +
4*d*(k - b*v - e*v^2)])/(2*d))}}
Obviously that's two equations. Suppose I just use one of them. Then I'd run:

FindFit[myData, myIFunction,{a,b,c,d,e},v]

5. i want know where is the problem when i do :

[PHP]
FindFit[Transpose[{xtab, ytab}],
a*y + b*x + c*x*y + d*y^2 + e*y^2, {a, b, c, d, e}, {x, y}]

FindFit::fitc: "\!$$\* StyleBox[\"\\\"Number of coordinates (\\\"\", \"MT\"]$$\!$$\* StyleBox[\"1\", \"MT\"]$$\!$$\* StyleBox[\"\\\") is not equal to the number of variables (\\\"\", \"MT\"]$$\!$$\* StyleBox[\"2\", \"MT\"]$$\!$$\* StyleBox[\"\\\").\\\"\", \"MT\"]$$ "
[/PHP]

i add an another coordinates, i do this
[PHP]ztab = xtab*ytab;
FindFit[Transpose[{xtab, ytab, ztab}],
a*y + b*x + c*x*y + d*y^2 + e*y^2, {a, b, c, d, e}, {x, y}]
{a -> 8.38184*10^-16, b -> -6.49935*10^-17, c -> 1.,
d -> -5.5458*10^-16, e -> -1.95062*10^-16}[/PHP]

but, the resultats are wrong,

hhhh, sorry showsend, what i do now

6. You mean you do this:

Code:
ztab = xtab*ytab;
myvals = FindFit[Transpose[{xtab, ytab, ztab}],
a*y + b*x + c*x*y + d*y^2 + e*y^2, {a, b, c, d, e}, {x, y}]
{a -> 8.38184*10^-16, b -> -6.49935*10^-17, c -> 1.,
d -> -5.5458*10^-16, e -> -1.95062*10^-16}
myfun[x_, y_] := a*y + b*x + c*x*y + d*y^2 + e*y^2 /. myvals;
Plot3D[myfun[x, y], {x, 1, 5}, {y, 1, 5}]
and the plot does not look like what it should look like? If that is the case then I don't know what's wrong because the code looks ok to me.

7. but when i change ztab the coefficients a,b,c,d,e changes, can i use the definition of D(I,V)=integral of VdI from 0 to I;
what can i do