
3-D Interpolation and Smoothing in Maple 16
Creating 3-D plots from discrete data has never been easier using the new smoothing and interpolation techniques in Maple 16.
• |
The smoothing algorithm allows you to generate a smooth surface that approximates your noisy data.
|
• |
The interpolation method generates a surface which matches your data points exactly, regardless of whether the data points lie on a uniform or non-uniform grid.
|
|
Details and Examples
|
|
> |
with(LinearAlgebra): with(CurveFitting): with(plots): with(Statistics): randomize():
|
|
Smoothing
|
|
In this example, we are assuming that we have a collection of 2-dimensional independent data for which the 1-dimensional dependent data has some error component or is known to be noisy. The presence of noise implies that whatever surface this data represents does not necessarily pass through the given dependent data points. In this case, a surface is approximated by numerically smoothing the data using the lowess algorithm. For any given point to be plotted a window of close enough, surrounding data points will be used to compute a local, weighted, low order fit.
The new command ScatterPlot3D, from the Statistics package, provides a smoothed plot of the 2-D noisy data.
The independent data does not need to be regularly spaced, and is supplied as an n-by-3 Array or Matrix. Each of the n rows represents an individual point. The columns are the x-, y-, and z-values. Here is an example. First, we'll look down upon the projection of the data points onto the x-y plane, and thus visualize the layout and spacing of the 2-D dependent data values.
> |
X := Sample(Uniform(-50,50),175):
|
> |
Y := Sample(Uniform(-50,50),175):
|
> |
Zerror := Sample(Normal(0,100),175):
|
> |
Z := Array(1..175,(i)->-(sin(Y[i]/20)*(X[i]-6)^2+(Y[i]-7)^2+Zerror[i])):
|
> |
XYZ := Matrix([[X],[Y],[Z]],datatype=float[8])^%T;
|
![XYZ := Matrix(175, 3, {(1, 1) = -5.9397834511560035, (1, 2) = -33.30916867431452, (1, 3) = -1639.7773014607262, (2, 1) = -17.868429349219618, (2, 2) = 15.074322451528488, (2, 3) = -314.2340700828792, (3, 1) = 28.36021487030426, (3, 2) = -33.7306549047331, (3, 3) = -1240.0533844232964, (4, 1) = -3.5722776429291585, (4, 2) = -16.66383185978998, (4, 3) = -546.3177546314236, (5, 1) = -.7484994433608634, (5, 2) = 18.70312215449536, (5, 3) = -131.90366425272734, (6, 1) = -36.58876351596092, (6, 2) = -31.171655455808555, (6, 3) = 427.1851926502871, (7, 1) = 38.485425981832904, (7, 2) = -3.6798890112897595, (7, 3) = 178.8978185967439, (8, 1) = -6.43421429833446, (8, 2) = -46.988949786990055, (8, 3) = -2857.6252737193117, (9, 1) = 44.0744474586329, (9, 2) = 6.471976104643062, (9, 3) = -500.37161340637516, (10, 1) = 3.5528192204783835, (10, 2) = 20.279178825823692, (10, 3) = -89.9296874536325, (11, 1) = -31.98817291819498, (11, 2) = -44.09303555020641, (11, 3) = -1552.963605161339, (12, 1) = 11.94512944171207, (12, 2) = 34.52492315165037, (12, 3) = -904.246409274692, (13, 1) = -22.08294133479192, (13, 2) = 40.11415521123874, (13, 3) = -1785.9653108321188, (14, 1) = -14.165626604488722, (14, 2) = -42.43695918979582, (14, 3) = -2092.0518860098678, (15, 1) = 7.525314821404216, (15, 2) = -2.4748480808763915, (15, 3) = -64.79048392275945, (16, 1) = 48.180985819176385, (16, 2) = 45.51084236436657, (16, 3) = -2702.041370724159, (17, 1) = 43.962663649880014, (17, 2) = 40.72421352877798, (17, 3) = -2530.463015776251, (18, 1) = -7.499443803723757, (18, 2) = -26.74285387275168, (18, 3) = -930.8951217626627, (19, 1) = 44.693060280275105, (19, 2) = -24.457213766703934, (19, 3) = 438.6543357909289, (20, 1) = -26.659102270945045, (20, 2) = .28761330559562737, (20, 3) = -56.31847001727824, (21, 1) = 20.633137559891836, (21, 2) = 8.166547456990983, (21, 3) = -13.914002874267283, (22, 1) = -7.672957431089856, (22, 2) = 38.908357331462014, (22, 3) = -1045.787782715187, (23, 1) = -3.275939203132573, (23, 2) = 8.171686424023086, (23, 3) = -14.687281577590937, (24, 1) = -21.89669204971947, (24, 2) = 11.560717254624663, (24, 3) = -534.5266426362529, (25, 1) = 6.612601233610604, (25, 2) = -34.9168758051168, (25, 3) = -1824.1283561252046, (26, 1) = -26.384850342152266, (26, 2) = -41.065183788955935, (26, 3) = -1284.9271639379292, (27, 1) = -47.34439744848436, (27, 2) = 36.68935586505536, (27, 3) = -3677.017197303269, (28, 1) = -28.30846296295586, (28, 2) = 36.68471571193558, (28, 3) = -1983.58426457367, (29, 1) = 48.95625501536291, (29, 2) = -.37503160711066386, (29, 3) = -18.098062378953657, (30, 1) = 15.137987923406229, (30, 2) = 28.81300719664094, (30, 3) = -671.2775454152537, (31, 1) = -.5440739863845394, (31, 2) = 9.229046996076008, (31, 3) = 7.178062567897168, (32, 1) = 42.1014773837212, (32, 2) = .7146210632886749, (32, 3) = 39.14593989962606, (33, 1) = -12.988465460624766, (33, 2) = 39.978548735345115, (33, 3) = -1298.4690486469074, (34, 1) = -6.2161508110094275, (34, 2) = -9.0889210884732, (34, 3) = -75.51433595132357, (35, 1) = -16.27923575004496, (35, 2) = 48.74007364786482, (35, 3) = -2207.015001204474, (36, 1) = -4.937739120894655, (36, 2) = 31.88430857988979, (36, 3) = -806.225147761428, (37, 1) = -16.72717497230873, (37, 2) = 18.891087232740333, (37, 3) = -606.372606575046, (38, 1) = 38.87147386992666, (38, 2) = -22.318033166863728, (38, 3) = 126.77959922471854, (39, 1) = 30.500171169708494, (39, 2) = -24.207797806982644, (39, 3) = -245.81268463603462, (40, 1) = 9.895804782525353, (40, 2) = 25.23134614239997, (40, 3) = -356.1795900168158, (41, 1) = -19.284928142719295, (41, 2) = .762457552807092, (41, 3) = -151.62384648265908, (42, 1) = 7.639476243356249, (42, 2) = -31.325996501239505, (42, 3) = -1473.5397452623336, (43, 1) = 23.57238884746056, (43, 2) = 26.831192892791208, (43, 3) = -649.3195959718685, (44, 1) = 27.43634927606996, (44, 2) = 39.39925103104089, (44, 3) = -1638.3967847926779, (45, 1) = 29.120929355982014, (45, 2) = -18.796299348021293, (45, 3) = -462.5217677878645, (46, 1) = -25.85242918986953, (46, 2) = -25.63499075724228, (46, 3) = -117.25523836495987, (47, 1) = -35.216357714072274, (47, 2) = 49.848114708419985, (47, 3) = -3015.6334018742155, (48, 1) = -45.790012671222335, (48, 2) = 47.79980804442174, (48, 3) = -3668.5318772910464, (49, 1) = -29.39080871659413, (49, 2) = 6.136376421806602, (49, 3) = -316.9842594665352, (50, 1) = 24.75898544760051, (50, 2) = 39.2388783895492, (50, 3) = -1365.0658865372925, (51, 1) = -36.280691468006125, (51, 2) = -19.658076696029713, (51, 3) = 801.9332483741492, (52, 1) = -28.79321881266548, (52, 2) = -10.19163353561838, (52, 3) = 254.81536655434772, (53, 1) = -6.119839311369333, (53, 2) = -23.934959319196324, (53, 3) = -826.3283822499292, (54, 1) = -41.51509405703607, (54, 2) = -.696788488766245, (54, 3) = 125.21045066826119, (55, 1) = 19.089029155967935, (55, 2) = -49.48100921192676, (55, 3) = -3091.209267113026, (56, 1) = 32.534253616532965, (56, 2) = 6.348691349405335, (56, 3) = -412.9250387252797, (57, 1) = -27.368652336574996, (57, 2) = 9.189003181275446, (57, 3) = -575.8804118088524, (58, 1) = 24.313423217249493, (58, 2) = 22.415410877386506, (58, 3) = -283.5879791610079, (59, 1) = 48.32397446496999, (59, 2) = -16.989620247401014, (59, 3) = 828.7917817211008, (60, 1) = 28.151840785727515, (60, 2) = -7.299835142890068, (60, 3) = -196.44827330324782, (61, 1) = 14.467698057828798, (61, 2) = 6.000660569092275, (61, 3) = 24.771323818981255, (62, 1) = -19.61066483426348, (62, 2) = -13.489324154626438, (62, 3) = -135.6070188173254, (63, 1) = 48.24156024599195, (63, 2) = -19.991710063585877, (63, 3) = 646.3849933446089, (64, 1) = 27.259500997177796, (64, 2) = -24.346291699072086, (64, 3) = -471.7615065897811, (65, 1) = -28.01118954374504, (65, 2) = 41.50987401697708, (65, 3) = -2404.5405499882504, (66, 1) = 35.28364776480963, (66, 2) = 30.163948654191927, (66, 3) = -1423.460168262091, (67, 1) = -6.503212805696421, (67, 2) = 34.745422055693396, (67, 3) = -811.0042018993295, (68, 1) = -20.63700258854476, (68, 2) = 18.97943101198642, (68, 3) = -822.5883818552766, (69, 1) = 7.717275903251938, (69, 2) = 9.418283521126504, (69, 3) = 129.392096356843, (70, 1) = 38.33884960657137, (70, 2) = 22.25299954594817, (70, 3) = -1177.9964749555309, (71, 1) = 13.582679516907866, (71, 2) = -15.864858230069757, (71, 3) = -684.2246409261886, (72, 1) = -22.788433665249052, (72, 2) = -29.949297372352667, (72, 3) = -517.8015945064188, (73, 1) = 48.88785346313024, (73, 2) = 47.72368244638422, (73, 3) = -2902.0713517506833, (74, 1) = -36.016047879236645, (74, 2) = 11.700209313476364, (74, 3) = -1026.7976506580337, (75, 1) = 20.899387693542167, (75, 2) = 34.15429192688785, (75, 3) = -1024.1661125169667, (76, 1) = -13.261126076474582, (76, 2) = 31.483930701450973, (76, 3) = -1017.5167469350976, (77, 1) = -29.117571007720812, (77, 2) = .8138457149615945, (77, 3) = 9.641931228541566, (78, 1) = -13.635904112821905, (78, 2) = -33.79520535877385, (78, 3) = -1405.9904165849734, (79, 1) = 4.920447575533672, (79, 2) = 6.153229877222387, (79, 3) = -0.8941925074702539e-1, (80, 1) = 17.600062099552034, (80, 2) = 21.440590780893885, (80, 3) = -195.18252239682718, (81, 1) = -49.77646987473301, (81, 2) = -43.47648169450664, (81, 3) = 62.57111364500433, (82, 1) = -47.74124420865663, (82, 2) = -17.94769595305221, (82, 3) = 1534.1621545607134, (83, 1) = 35.72320975270978, (83, 2) = 19.538596486394994, (83, 3) = -923.3234512815852, (84, 1) = -4.7195416485422825, (84, 2) = -5.547220157244901, (84, 3) = -252.89497810024693, (85, 1) = -49.88163176564127, (85, 2) = 26.14394873643316, (85, 3) = -3400.3224870894496, (86, 1) = -46.91151752973853, (86, 2) = -19.965288471239994, (86, 3) = 1706.1479328193423, (87, 1) = -23.85609306304125, (87, 2) = -33.16908545450238, (87, 3) = -725.9270833516655, (88, 1) = -38.33004593761239, (88, 2) = -42.06127345789235, (88, 3) = -728.9771703001193, (89, 1) = 18.233380827431063, (89, 2) = -33.17909218939534, (89, 3) = -1651.0258327122287, (90, 1) = -29.194208291307845, (90, 2) = -39.73226336460086, (90, 3) = -1224.9898450801943, (91, 1) = 22.135852353243962, (91, 2) = 36.94558251605382, (91, 3) = -1105.1294459106039, (92, 1) = -27.83605960122658, (92, 2) = -.8403229434334136, (92, 3) = -53.793989191566794, (93, 1) = -16.175477185814543, (93, 2) = 19.988116226866353, (93, 3) = -594.5056170028219, (94, 1) = -26.852729792287533, (94, 2) = 16.659448499968192, (94, 3) = -971.2719353303916, (95, 1) = -22.276075293139296, (95, 2) = 24.409338994848866, (95, 3) = -955.8469696261711, (96, 1) = -48.25201033973238, (96, 2) = -23.7297560085032, (96, 3) = 1746.8930267119515, (97, 1) = 43.76360283321324, (97, 2) = 24.48810021583479, (97, 3) = -1566.7220603967799, (98, 1) = -19.685303961621127, (98, 2) = -40.31604083898945, (98, 3) = -1818.3068011800563, (99, 1) = -4.432935829824395, (99, 2) = -49.77492305297534, (99, 3) = -3024.646944279653, (100, 1) = 33.05926757131755, (100, 2) = -18.99175605036316, (100, 3) = -230.5069327651789, (101, 1) = -26.675830968826087, (101, 2) = 1.2196046968787613, (101, 3) = -163.98002051808783, (102, 1) = 37.49297729584808, (102, 2) = -28.991225491562044, (102, 3) = -317.8451695090786, (103, 1) = 26.360062021186224, (103, 2) = 3.5286642227915195, (103, 3) = -84.91345384591095, (104, 1) = 28.620475984565516, (104, 2) = -40.00431074525106, (104, 3) = -1684.573204494527, (105, 1) = -8.626071247568056, (105, 2) = 15.951150508812105, (105, 3) = -392.2975368890458, (106, 1) = -26.929832567733534, (106, 2) = 7.900566007404684, (106, 3) = -455.80866144149377, (107, 1) = 41.454303764346946, (107, 2) = -42.34107621691355, (107, 3) = -1342.3834060337597, (108, 1) = 38.791224381823824, (108, 2) = -28.31336623236411, (108, 3) = -254.1598498045391, (109, 1) = -23.700186647475864, (109, 2) = 6.71525167411815, (109, 3) = -178.66610998484649, (110, 1) = 46.477611093838874, (110, 2) = 38.46706283750727, (110, 3) = -2705.762316789356, (111, 1) = 1.4217703260267527, (111, 2) = -9.864148537849935, (111, 3) = -413.5541673382436, (112, 1) = 5.499362979332091, (112, 2) = 34.976437451849264, (112, 3) = -717.4362586609559, (113, 1) = 3.6187080878030002, (113, 2) = -36.71009977415402, (113, 3) = -2000.3771648775985, (114, 1) = -28.147198931011975, (114, 2) = 18.13156528619308, (114, 3) = -962.4107423461998, (115, 1) = -31.107277485465545, (115, 2) = -40.623203690427275, (115, 3) = -1185.2281195817227, (116, 1) = -8.964077624733036, (116, 2) = 20.598541957230836, (116, 3) = -350.7073584536123, (117, 1) = 37.18147531771547, (117, 2) = -2.9258496667399996, (117, 3) = 87.01297650910561, (118, 1) = 45.098712621274345, (118, 2) = 41.46878885405599, (118, 3) = -2416.0725299578176, (119, 1) = 18.530469991250342, (119, 2) = 18.068451626665365, (119, 3) = -225.14447770301837, (120, 1) = -40.40806444616981, (120, 2) = -31.625422580892028, (120, 3) = 807.4618416795008, (121, 1) = 36.305542383815904, (121, 2) = -21.417015738157374, (121, 3) = -91.59004972339035, (122, 1) = -8.041948659341301, (122, 2) = -48.87395247518933, (122, 3) = -2971.5321820333656, (123, 1) = -26.927805093607983, (123, 2) = -4.4109083538223715, (123, 3) = 145.31707650647553, (124, 1) = -7.196909475471315, (124, 2) = -12.257023562892734, (124, 3) = -387.66640392756045, (125, 1) = -27.686901412414635, (125, 2) = 26.420134933231708, (125, 3) = -1680.297175428206, (126, 1) = 15.199054629734462, (126, 2) = -11.311430544310063, (126, 3) = -353.78334258654286, (127, 1) = -16.84422177189576, (127, 2) = 33.074704558544184, (127, 3) = -1191.7595197925857, (128, 1) = 19.884634702794415, (128, 2) = 43.767772748804816, (128, 3) = -1449.0611783674335, (129, 1) = -1.071360318503345, (129, 2) = -19.482144254980184, (129, 3) = -462.6606723222883, (130, 1) = 30.962134410311265, (130, 2) = -36.05342079524713, (130, 3) = -1294.2451937703152, (131, 1) = 44.94468436804702, (131, 2) = 32.164005357049604, (131, 3) = -2285.7203406348963, (132, 1) = 20.263274894305894, (132, 2) = -25.49918089097787, (132, 3) = -950.5069672824037, (133, 1) = -42.160336872399384, (133, 2) = 38.50886618808529, (133, 3) = -3225.0367695336545, (134, 1) = -38.92689885495895, (134, 2) = 41.40359286768721, (134, 3) = -2826.6302667372397, (135, 1) = 12.566517896903427, (135, 2) = -40.88165553811164, (135, 3) = -2272.333193061874, (136, 1) = 4.154850939941888, (136, 2) = .17363288219475237, (136, 3) = 158.90720314219757, (137, 1) = -44.3994170693485, (137, 2) = -29.4885971159339, (137, 3) = 1069.64804909218, (138, 1) = -44.658519534617035, (138, 2) = 37.96463358446917, (138, 3) = -3386.398286267373, (139, 1) = 7.1870512257623105, (139, 2) = -25.519931950218965, (139, 3) = -1118.9693520468024, (140, 1) = 44.592863254078765, (140, 2) = 32.4461432284147, (140, 3) = -2126.371529313945, (141, 1) = 26.233067266834254, (141, 2) = 14.271200339549196, (141, 3) = -340.3834511232196, (142, 1) = -43.30419756620112, (142, 2) = 32.606764802159304, (142, 3) = -3047.34689430829, (143, 1) = -42.70669636331128, (143, 2) = -34.0143424107332, (143, 3) = 760.5572713592038, (144, 1) = -32.63054188520222, (144, 2) = 46.5490641455185, (144, 3) = -2527.26345978372, (145, 1) = -46.87044518386556, (145, 2) = -11.824825942762082, (145, 3) = 1309.408257475229, (146, 1) = 33.28525140586305, (146, 2) = -28.814793930999784, (146, 3) = -522.5474268641441, (147, 1) = -8.123901972182779, (147, 2) = -34.00582701115552, (147, 3) = -1388.3560545469172, (148, 1) = -16.491248468822896, (148, 2) = 4.139801952739695, (148, 3) = -24.949954012455308, (149, 1) = 48.96240824356208, (149, 2) = 44.25761676582627, (149, 3) = -2838.225614673019, (150, 1) = -21.15105896355042, (150, 2) = -7.959115594228372, (150, 3) = 60.36595914283298, (151, 1) = 19.820004205652836, (151, 2) = -7.744224994147039, (151, 3) = -206.25279670134714, (152, 1) = 1.257062051065951, (152, 2) = 44.993197086159725, (152, 3) = -1537.3620392499417, (153, 1) = 21.077423355166786, (153, 2) = -23.55228327354839, (153, 3) = -664.5597120920124, (154, 1) = -42.512982412856324, (154, 2) = -20.028981526360333, (154, 3) = 1295.1818590503422, (155, 1) = -21.678824753517524, (155, 2) = -3.805445357881034, (155, 3) = 70.42723850422766, (156, 1) = -49.277744362895326, (156, 2) = -19.529429443465073, (156, 3) = 1776.9274722649077, (157, 1) = -4.84529942907843, (157, 2) = 19.03429531941036, (157, 3) = -151.56806900959097, (158, 1) = 2.8001279793995906, (158, 2) = -11.132712862056536, (158, 3) = -335.1509230804099, (159, 1) = 18.70105488290949, (159, 2) = -4.771820882044729, (159, 3) = -98.2700775059379, (160, 1) = 12.422342510055259, (160, 2) = 34.01384964839731, (160, 3) = -814.8126668250393, (161, 1) = -21.639929411177196, (161, 2) = -47.86995232681157, (161, 3) = -2436.445568354756, (162, 1) = 26.84103238006476, (162, 2) = -41.55411558200524, (162, 3) = -1891.260119561242, (163, 1) = -9.573010858952678, (163, 2) = -10.029261836482938, (163, 3) = -213.23159650973543, (164, 1) = -40.74906935624335, (164, 2) = 43.677291454211925, (164, 3) = -3091.575932677467, (165, 1) = 18.556687383653838, (165, 2) = 31.29427124889098, (165, 3) = -711.0275183508754, (166, 1) = -35.24016028732198, (166, 2) = -11.065164547743855, (166, 3) = 652.2250157858072, (167, 1) = -21.45882263850103, (167, 2) = -2.6256864172080085, (167, 3) = -60.541868676197836, (168, 1) = 49.58671125602973, (168, 2) = -1.174292867475998, (168, 3) = 174.79296219019562, (169, 1) = -46.50772820042859, (169, 2) = -36.3499315759516, (169, 3) = 749.8102905319306, (170, 1) = -11.402490165222886, (170, 2) = 44.93506176554554, (170, 3) = -1684.6113502432145, (171, 1) = 7.868921388519425, (171, 2) = 6.353728977902797, (171, 3) = -13.997636036034633, (172, 1) = 9.450866200908777, (172, 2) = 5.138754638444475, (172, 3) = 5.854563048414562, (173, 1) = 40.68626277665878, (173, 2) = 44.34216772941707, (173, 3) = -2475.205899949261, (174, 1) = -2.6751846186269006, (174, 2) = 20.742211573151437, (174, 3) = -136.6474275250191, (175, 1) = 22.801039285581723, (175, 2) = -27.971627419697864, (175, 3) = -918.081796377342}, datatype = float[8])](/view.aspx?SI=132223/433229/4bceab06e2b4d0bd1a3fc35390810d7e.gif)
> |
ScatterPlot3D(XYZ, axes=box, orientation=[20,0,0]);
|

> |
ScatterPlot3D(XYZ, lowess, grid=[25,25], axes=box, orientation=[20,70,0]);
|

Here is another example, which reads in the n-by3 data from a file.
> |
M:=ImportMatrix(cat(kernelopts(mapledir),"/data/plotting/irregulardata3D.csv"), source=csv,datatype=float[8]):
|
> |
Ppt := pointplot3d(M,axes=box,style=patchnogrid,symbolsize=15,color=red, labels=[x,y,z]):
|
> |
display(Ppt,orientation=[90,0,0]);
|

The default options for the ScatterPlot3D command are to use an order 2 fitting quadratic form, and to use a window of width 1/3 of the original domain in each of the x- and y-directions.
On the right below is the smoothed surface, while on the left is a slightly transparent view of the same surface overlaid with a point-plot of the original data points.
> |
Ploess := ScatterPlot3D( M, lowess ):
|
> |
display(Array([ display([Ppt,Ploess]), display(Ploess,style=patch,color=RGB(0.0,0.4,0.6)) ]),view=700..860,axes=box,orientation=[54,78,-15], transparency=0.0);
|
|
|
|