Guest User

Untitled

a guest
Oct 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. equation = c2[x] f''[x] + c1[x] f'[x] + c0[x] f[x] + d0[x] == 0
  2.  
  3. grid = {1.,2.,3.,4.};
  4.  
  5. c = (Sinh[1/2 (g x^4 + x^2)] + p^3 x/ (g - x^3)) g^2 x^2;
  6.  
  7. (* ... *)
  8. p = 3.; (* actually some computation *)
  9. g = {0.714, 0.429,0.734, 0.921}; (* some other computation *)
  10. cComputed = Block[{x = grid}, c]
  11. (* use this vector c to construct and solve the discretized equation *)
  12.  
  13. cPartlyComputed = g^2({1.`, 4.`, 9.`, 16.`} Sinh[{0.5`, 8.`, 40.5`, 128.`} g + {0.5`, 2.`, 4.5`, 8.`}]
  14. + p^3 {1.`, 8.`, 27.`, 64.`}/(g - {1.`, 8.`, 27.`, 64.`}));
  15.  
  16. cTry = c /. x -> grid;
  17.  
  18. ClearAll[CircleTimes, CirclePlus]
  19. Attributes[CirclePlus] = Attributes[CircleTimes] = Complement[Attributes[Plus], {Listable, Protected}];
  20. Verbatim[CircleTimes][a_] := a;
  21. Verbatim[CirclePlus][a_] := a;
  22. numericOrList[a_] := NumericQ[a] || Head[a] === List;
  23. a_[CircleTimes]b_ := a*b /; numericOrList[a] && numericOrList[b];
  24. a_[CirclePlus]b_ := a + b /; numericOrList[a] && numericOrList[b];
  25. a_[CircleTimes](b_[CirclePlus]c_) :=
  26. a[CircleTimes]b[CirclePlus]a[CircleTimes]c /; numericOrList[a]
  27. a_[CircleTimes]x1_[CirclePlus]a_[CircleTimes]x2_ :=
  28. a[CircleTimes](x1 + x2) /; numericOrList[x1] && numericOrList[x2];
  29.  
  30.  
  31. evaluate[expression_, var_, grid_] := Hold[Evaluate[
  32. expression /. {Plus -> CirclePlus, Times -> CircleTimes} /. var -> grid
  33. ]] /. {CirclePlus -> Plus, CircleTimes -> Times}
  34.  
  35. evaluate[c,x,grid]
  36.  
  37. c2=-5832. - 432. x^2 - 1728. f x^3 - 12. (32. + 72. d1f + 144. f^2 - 27. p^4) x^4
  38. - 24. f (32. + 72. d1f - 27. p^4) x^5
  39.  
  40. evaluate[c2,x,grid]
Add Comment
Please, Sign In to add comment