Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- equation = c2[x] f''[x] + c1[x] f'[x] + c0[x] f[x] + d0[x] == 0
- grid = {1.,2.,3.,4.};
- c = (Sinh[1/2 (g x^4 + x^2)] + p^3 x/ (g - x^3)) g^2 x^2;
- (* ... *)
- p = 3.; (* actually some computation *)
- g = {0.714, 0.429,0.734, 0.921}; (* some other computation *)
- cComputed = Block[{x = grid}, c]
- (* use this vector c to construct and solve the discretized equation *)
- cPartlyComputed = g^2({1.`, 4.`, 9.`, 16.`} Sinh[{0.5`, 8.`, 40.5`, 128.`} g + {0.5`, 2.`, 4.5`, 8.`}]
- + p^3 {1.`, 8.`, 27.`, 64.`}/(g - {1.`, 8.`, 27.`, 64.`}));
- cTry = c /. x -> grid;
- ClearAll[CircleTimes, CirclePlus]
- Attributes[CirclePlus] = Attributes[CircleTimes] = Complement[Attributes[Plus], {Listable, Protected}];
- Verbatim[CircleTimes][a_] := a;
- Verbatim[CirclePlus][a_] := a;
- numericOrList[a_] := NumericQ[a] || Head[a] === List;
- a_[CircleTimes]b_ := a*b /; numericOrList[a] && numericOrList[b];
- a_[CirclePlus]b_ := a + b /; numericOrList[a] && numericOrList[b];
- a_[CircleTimes](b_[CirclePlus]c_) :=
- a[CircleTimes]b[CirclePlus]a[CircleTimes]c /; numericOrList[a]
- a_[CircleTimes]x1_[CirclePlus]a_[CircleTimes]x2_ :=
- a[CircleTimes](x1 + x2) /; numericOrList[x1] && numericOrList[x2];
- evaluate[expression_, var_, grid_] := Hold[Evaluate[
- expression /. {Plus -> CirclePlus, Times -> CircleTimes} /. var -> grid
- ]] /. {CirclePlus -> Plus, CircleTimes -> Times}
- evaluate[c,x,grid]
- c2=-5832. - 432. x^2 - 1728. f x^3 - 12. (32. + 72. d1f + 144. f^2 - 27. p^4) x^4
- - 24. f (32. + 72. d1f - 27. p^4) x^5
- evaluate[c2,x,grid]
Add Comment
Please, Sign In to add comment