Newer
Older
Lecture_repo / Lectures_my / NumMet / 2016 / Lecture3 / examples / two-dim.nb
@mchrzasz mchrzasz on 12 Oct 2016 1 KB fixed small things
  1. In[1]:= f[x_, y_] := Cos[x + y]
  2. We need rho = (2 + n over n) terms to describe multinomial in 2 variables of degree <= n
  3. In[3]:= n = 1
  4. Out[3]= 1
  5. In[6]:= ρ = Binomial[n + 2, n]
  6. Out[6]= 3
  7. In[7]:= pointsA = {
  8. {0, 0},
  9. {0, π/4},
  10. {π/4, 0}
  11. };
  12. In[33]:= pointsB = {
  13. {0, 0},
  14. {π/8, π/8},
  15. {π/4, π/4}
  16. };
  17. Set up Vandermonde matrix
  18. In[8]:= VanderMondeLine[point_] := Block[{x = point[[1]], y = point[[2]]},
  19. Return[{1, x, y}]
  20. ]
  21. In[35]:= VA = VanderMondeLine /@ pointsA
  22. VB = VanderMondeLine /@ pointsB
  23. Out[35]= {{1,0,0},{1,0,π/4},{1,π/4,0}}
  24. Out[36]= {{1,0,0},{1,π/8,π/8},{1,π/4,π/4}}
  25. In[14]:= a = {a0, ax, ay};
  26. In[37]:= ffA = f @@@ pointsA
  27. ffB = f @@@ pointsB
  28. Out[37]= {1,1/Sqrt[2],1/Sqrt[2]}
  29. Out[38]= {1,1/Sqrt[2],0}
  30. In[39]:= Solve[VA.a == ffA, a]
  31. intA = VanderMondeLine[{x, y}].a //. %[[1]]
  32. Out[39]= {{a0->1,ax->(2 (-2+Sqrt[2]))/π,ay->(2 (-2+Sqrt[2]))/π}}
  33. Out[40]= 1+(2 (-2+Sqrt[2]) x)/π+(2 (-2+Sqrt[2]) y)/π
  34. In[44]:= VB.a
  35. Out[44]= {a0,a0+(ax π)/8+(ay π)/8,a0+(ax π)/4+(ay π)/4}
  36. In[43]:= Solve[VB.a == ffB, a]
  37. Out[43]= {}
  38. In[25]:= ContourPlot[
  39. f[x, y],
  40. {x, 0, π/4},
  41. {y, 0, π /4}
  42. ]
  43.  
  44. Out[25]=
  45. In[32]:= ContourPlot[
  46. intA,
  47. {x, 0, π/4},
  48. {y, 0, π /4}
  49. ]
  50. Out[32]=