diff options
author | Karl Berry <karl@freefriends.org> | 2023-07-24 20:23:44 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-07-24 20:23:44 +0000 |
commit | 986b951b03bf91c8873928791b4f90fa96a91fec (patch) | |
tree | b9f096ff7e93da2b571625d040be9e5727468605 /Master/texmf-dist/tex | |
parent | ff358decc98f9c2b462ff4685493a85850279b4f (diff) |
luanumint (24jul23)
git-svn-id: svn://tug.org/texlive/trunk@67725 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/luanumint/luanumint.sty | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/luanumint/luanumint.sty b/Master/texmf-dist/tex/lualatex/luanumint/luanumint.sty new file mode 100644 index 00000000000..aca4de02158 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/luanumint/luanumint.sty @@ -0,0 +1,301 @@ +% The luanumint package +% version 1.0 +% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt. +%Authors: Chetan Shirore and Ajit Kumar + +\ProvidesPackage{luanumint}[1.0] +\RequirePackage{luacode,breqn,xkeyval} +\begin{luacode*} +function checksign(x) + if x >=0 then + return ' + ' + else + return '' + end +end + +function mathrnd(num, numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end + +function luamidpt (f,a,b,n,trun) + local trun = trun or 4 + local h = (b - a) / n + local sum = 0 + local var = a + h/2 + for i = 1, n do + sum = sum + f(var) + var = var + h + end + return mathrnd(sum*h,trun) +end + +function luamidptSteps (f,a,b,n,nm,trun) + local trun = trun or 4 + local nm = nm or "f" + local h = (b - a) / n + local sum = 0 + local var = a + (h/2) + local str = " = "..mathrnd(h,trun)..'\\left[' + local otstr = mathrnd(h,trun)..'\\left(' + for i = 1, n do + if i>=1 and i<=n-1 then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(f(var),trun)..checksign(f(var+h),trun) + end + if i== n then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..")" + otstr = otstr ..mathrnd(f(var),trun) + end + var = var + h + end + return str .."\\right] \\\\ = "..otstr.."\\right) \\\\ = "..mathrnd(sum*mathrnd(h,trun),trun) +end + +function luatrapz (f,a,b,n,trun) + local trun = trun or 4 + local h = (b - a) / n + local sum = 0 + local var = a + for i = 1, n+1 do + if i== 1 or i == n+1 then + sum = sum + f(var) + else + sum = sum + 2*f(var) + end + var = var + h + end + return mathrnd(sum*h/2,trun) +end + +function luatrapzsteps (f,a,b,n,nm,trun) + local trun = trun or 4 + local nm = nm or "f" + local h = (b - a) / n + local sum = 0 + local var = a + local str = " = "..mathrnd(h/2,trun)..'\\left[' + local otstr = mathrnd(h/2,trun)..'\\left(' + for i = 0, n do + if i== 0 then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..") +" + otstr = otstr ..mathrnd(f(var),trun)..checksign(f(var+h),trun) + end + if i>=1 and i<=n-1 then + sum = sum + mathrnd(2*f(var),trun) + str = str .."2"..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(2*f(var),trun)..checksign(f(var+h),trun) + end + if i== n then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..")" + otstr = otstr ..mathrnd(f(var),trun) + end + var = var + h + end + return str .."\\right] \\\\ = "..otstr.."\\right) \\\\ = "..mathrnd(sum*mathrnd(h/2,trun),trun) +end + +function luasimpsononethird (f,a,b,n,trun) + if (not(n % 2 == 0)) then error("Number of subintervals should be even.") end + local trun = trun or 4 + local h = (b - a) / n + local sum = 0 + local var = a + for i = 0, n do + if i== 0 or i ==n then + sum = sum + f(var) + end + if i>=1 and i<=n-1 and (i % 2 == 0) then + sum = sum + 2*f(var) + end + if i>=1 and i<=n-1 and (not(i % 2 == 0)) then + sum = sum + 4*f(var) + end + var = var + h + end + return mathrnd(sum*h/3,trun) +end + +function luasimpsononethirdsteps (f,a,b,n,nm,trun) + if (not(n % 2 == 0)) then error("Number of subintervals should be even.") end + local trun = trun or 4 + local nm = nm or "f" + local h = (b - a) / n + local sum = 0 + local var = a + local str = " = "..mathrnd(h/3,trun)..'\\left[' + local otstr = mathrnd(h/3,trun)..'\\left(' + for i = 0, n do + if i== 0 then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..") +" + otstr = otstr ..mathrnd(f(var),trun)..checksign(f(var+h),trun) + end + if i>=1 and i<=n-1 and (i % 2 == 0) then + sum = sum + mathrnd(2*f(var),trun) + str = str .."2"..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(2*f(var),trun)..checksign(f(var+h),trun) + end + if i>=1 and i<=n-1 and (not(i % 2 == 0)) then + sum = sum + mathrnd(4*f(var),trun) + str = str.."4"..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(4*f(var),trun)..checksign(f(var+h),trun) + end + if i== n then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..")" + otstr = otstr ..mathrnd(f(var),trun) + end + var = var + h + end + return str .."\\right] \\\\ = "..otstr.."\\right) \\\\ = "..mathrnd(sum*mathrnd(h/3,trun),trun) +end + +function luasimpsonthreight (f,a,b,n,trun) + if (not(n % 3 == 0)) then error("No. of sub-intervals should be multiple of 3.") end + local trun = trun or 4 + local h = (b - a) / n + local sum = 0 + local var = a + + for i = 0, n do + if i== 0 or i ==n then + sum = sum + f(var) + end + if i>=1 and i<=n-1 and (i % 3 == 0) then + sum = sum + 2*f(var) + end + if i>=1 and i<=n-1 and (not(i % 3 == 0)) then + sum = sum + 3*f(var) + end + var = var + h + end + return mathrnd(sum*3*h/8,trun) +end + +function luasimpsonthreightsteps (f,a,b,n,nm,trun) + if (not(n % 3 == 0)) then error("No. of sub-intervals should be multip.") end + local trun = trun or 4 + local nm = nm or "f" + local h = (b - a) / n + local sum = 0 + local var = a + local str = " = "..mathrnd(3*h/8,trun)..'\\left[' + local otstr = mathrnd(3*h/8,trun)..'\\left(' + for i = 0, n do + if i== 0 then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..") +" + otstr = otstr ..mathrnd(f(var),trun)..checksign(f(var+h),trun) + end + if i>=1 and i<=n-1 and (i % 3 == 0) then + sum = sum + mathrnd(2*f(var),trun) + str = str .."2"..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(2*f(var),trun)..checksign(f(var+h),trun) + end + if i>=1 and i<=n-1 and (not(i % 3 == 0)) then + sum = sum + mathrnd(3*f(var),trun) + str = str.."3"..nm.."("..mathrnd(var,trun)..") + " + otstr = otstr ..mathrnd(3*f(var),trun)..checksign(f(var+h),trun) + end + if i== n then + sum = sum + mathrnd(f(var),trun) + str = str ..nm.."("..var..")" + otstr = otstr ..mathrnd(f(var),trun) + end + var = var + h + end + return str .."\\right] \\\\ = "..otstr.."\\right) \\\\ = "..mathrnd(sum*mathrnd(3*h/8,trun),trun) +end +\end{luacode*} + +% ========= KEY DEFINITIONS ========= +\define@key{someop}{a}{\def\mop@one{#1}}% +\define@key{someop}{b}{\def\mop@two{#1}}% +\define@key{someop}{n}{\def\mop@three{#1}}% +\define@key{someop}{func}{\def\mop@four{#1}}% +\define@key{someop}{trun}{\def\mop@five{#1}}% +% ========= KEY DEFAULTS ========= +\setkeys{someop}{a=0}% +\setkeys{someop}{b=1}% +\setkeys{someop}{n=6}% +\setkeys{someop}{func=f}% +\setkeys{someop}{trun=4}% +% ========= Defining Command ========= +\newcommand{\luaMidpt}[2][]{{% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() +tex.print(luamidpt(f,\mop@one,\mop@two,\mop@three,\mop@five)) +}% +}% +}% + +\newcommand{\luaMidptSteps}[2][]{\begingroup% +\setkeys{someop}{#1}% +\directlua{% + +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.sprint(luamidptSteps(f,\mop@one,\mop@two,\mop@three,'\mop@four',\mop@five)) +}% +\endgroup}% + +\newcommand{\luaTrapz}[2][]{{% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() +tex.print(luatrapz(f,\mop@one,\mop@two,\mop@three,\mop@five)) +}% +}% +}% + +\newcommand{\luaTrapzSteps}[2][]{\begingroup% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.sprint(luatrapzsteps(f,\mop@one,\mop@two,\mop@three,'\mop@four',\mop@five)) +}% +\endgroup}% + +\newcommand{\luaSimpsonOneThird}[2][]{{% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.print(luasimpsononethird(f,\mop@one,\mop@two,\mop@three,\mop@five)) +}% +}% +}% + +\newcommand{\luaSimpsonOneThirdSteps}[2][]{\begingroup% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.sprint(luasimpsononethirdsteps(f,\mop@one,\mop@two,\mop@three,'\mop@four',\mop@five)) +}% +\endgroup}% + + +\newcommand{\luaSimpsonThreeEighth}[2][]{{% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.print(luasimpsonthreight(f,\mop@one,\mop@two,\mop@three,\mop@five)) +}% +}% +}% + +\newcommand{\luaSimpsonThreeEighthSteps}[2][]{\begingroup% +\setkeys{someop}{#1}% +\directlua{% +tempsubexp = "("..\luastring{#2}..")" +local f = load("return function(x) return " ..tempsubexp.. "end",nil,"t",math)() tex.sprint(luasimpsonthreightsteps(f,\mop@one,\mop@two,\mop@three,'\mop@four',\mop@five)) +}% +\endgroup}% +\endinput
\ No newline at end of file |