# Cannot convert expression to function

Posted 10 years ago
4311 Views
|
6 Replies
|
4 Total Likes
|
 Please look at following picture. Why when I call f[0,0], values of variables x and y were not replaced by 0 and 0??? Still x, y in there
6 Replies
Sort By:
Posted 10 years ago
 Ok, thanks. I got it!
Posted 10 years ago
 Once created I cannot make this box go away In[1]:= Clear[a, b]; nmax = 10; mmax = 15; pts = Flatten[Table[{i - mmax/2, j - mmax/2, N[i^2 + j^2 - 5*i*j]}, {i, mmax}, {j, mmax}], 1]; f1 = Sum[a[i]*x^i, {i, nmax}]; f2 = Sum[b[i]*y^i, {i, nmax}]; fpp = Expand[f1*f2]; f = Function[{x, y}, Evaluate[fpp]]; EE = Expand[Sum[Sqrt[1/mmax^2*(f[pts[[i,1]], pts[[i,2]]] - pts[[i,3]])^2], {i, mmax*mmax}]];v = Join[Table[a[i], {i, nmax}], Table[b[i], {i, nmax}]];w = v /. NMinimize[EE, v][[2]];MapThread[Set, {v, w}];In[13]:= a[1]Out[13]= -0.024081In[14]:= b[10]Out[14]= 0.042064
Posted 10 years ago
 Thanks so much all. But I have other question, in following picture, I want to transfer value from result for parameters a and b. I know that I can use ./, but how I can use for long elements of table.Wanna a and b receive these values (yellow marked)
Posted 10 years ago
 Sorry for the double posting. I was seconds late...M.
Posted 10 years ago
 Hi,please try to provide the code rather than an image of it next time. You might want to try this code: nmax = 10; mmax = 10; k = 0; pts = List[]; pt = List[]; For[i = 1, j <= nmax, i++,   For[j = 1, j <= mmax, j++,    AppendTo[pt, i - nmax/2];    AppendTo[pt, j - nmax/2];   AppendTo[pt, N[i^2 + j^2 - 5*i*j]];   k = k + 1;   AppendTo[pts, pt];   pt = List[];   ]  ];f1 := Sum[Subscript[a, i]*x^i, {i, nmax}];f2 := Sum[Subscript[b, i]*y^i, {i, nmax}];fpp = Expand[f1*f2];fout[x_, y_] := Evaluate[fpp]If you then evaluatefout[0,0]that results in 0.M.
Posted 10 years ago
 Try f = Function[{x, y}, Evaluate[fpp]];