# ex:=A + B \cos(x); # nevaluate(ex, {$A$: 1, $B$: 3, $x$: np.linspace(0, 10, 10)}); import time # import matplotlib.pyplot as plt import numpy as np def test01(): start = time.time() ex:= \cos(x) \sin(y). xv = np.linspace(0, 3.14, 100); yv = np.linspace(0, 3.14, 100); z = np.array( nevaluate(ex, {$x$: xv, $y$: yv} ) ) end = time.time() # print("that took", end-start, "seconds") assert( abs( z[10, 20] - 0.563 ) < 0.001) print("Test 01 passed") # XV, YV=np.meshgrid(xv, yv) # plt.figure(figsize=(20, 10)) # ax = plt.axes(projection='3d') # ax.plot_surface(XV, YV, z, rstride=1, cstride=1, cmap='terrain', edgecolor=None) test01() def test02(): res = np.array(nevaluate( $3\cos(x)$, {$x$: [0]})) assert(abs(res[0] - 3.0) < 0.001) print("Test 02a passed") res = np.array(nevaluate( $3\cos(3 x + \pi/4)$, {$x$: [0]})) assert(abs(res[0] - 2.1213) < 0.001) print("Test 02b passed") test02() def test03(): res = np.array(nevaluate( $\pi x$, {$x$: [0,1,2]})) assert(np.max(res - np.array([0, 3.14, 6.28])) < 0.01) print("Test 03a passed") res = np.array(nevaluate( $x \pi$, {$x$: [0,1,2]})) assert(np.max(res - np.array([0, 3.14, 6.28])) < 0.01) print("Test 03b passed") res = np.array(nevaluate( $\pi + x$, {$x$: [0,1,2]})) assert(np.max(res - np.array([3.14, 4.14, 5.14])) < 0.01) print("Test 03c passed") res = np.array(nevaluate( $x + \pi$, {$x$: [0,1,2]})) assert(np.max(res - np.array([3.14, 4.14, 5.14])) < 0.01) print("Test 03d passed") test03() def test04(): res = np.array( nevaluate($3 \cos(5 x)$, {$x$: [0.1, 0.3]}) ) assert(np.max(res - np.array([2.6327, 0.2112])) < 0.01) print("Test 04a passed") xv = np.array([2.0, 5.0]) res = np.array( nevaluate($\sin(3.0*x)*\cos(-1/2 x)*\exp(-x**(2/5))$, {$x$: xv} )) assert(np.max(res - np.sin(3.0*xv)*np.cos(-1/2*xv)*np.exp(-xv**(2/5))) < 0.01) print("Test 04b passed") test04() ex:=\cos(v x); vv=0.2 substitute(ex, $v -> @(vv)$);