FEM2D_LEASTSQUARES C++ version Seek U(x,y), the solution of the least squares equation: Minimize L2 norm of U(x,y) - W(x,y), for W(x,y) given, with U(x,y) a piecewise linear function in the interior, and matching W(x,y) on the boundary. Reformulate this in terms of a finite element problem: ( U(x,y) - W(x,y), V(x,y) ) = 0 inside the region, U(x,y) = W(x,y) on the boundary The region is a rectangle, defined by: 0 = XL<= X <= XR = 1 0 = YB<= Y <= YT = 1 The finite element method is used, with piecewise linear basis functions on 3 node triangular elements. The corner nodes of the triangles are generated by an underlying grid whose dimensions are NX = 17 NY = 17 Number of nodes = 289 Number of elements = 512 K I J X Y U(x,y) W(x,y) 0 1 1 0 0 0 0 0 1 2 1 0.0625 0 0.0625 0.0625 0 2 3 1 0.125 0 0.125 0.125 0 3 4 1 0.1875 0 0.1875 0.1875 0 4 5 1 0.25 0 0.25 0.25 0 5 6 1 0.3125 0 0.3125 0.3125 0 6 7 1 0.375 0 0.375 0.375 0 7 8 1 0.4375 0 0.4375 0.4375 0 8 9 1 0.5 0 0.5 0.5 0 9 10 1 0.5625 0 0.5625 0.5625 0 10 11 1 0.625 0 0.625 0.625 0 11 12 1 0.6875 0 0.6875 0.6875 0 12 13 1 0.75 0 0.75 0.75 0 13 14 1 0.8125 0 0.8125 0.8125 0 14 15 1 0.875 0 0.875 0.875 0 15 16 1 0.9375 0 0.9375 0.9375 0 16 17 1 1 0 1 1 0 17 1 2 0 0.0625 0 0 0 18 2 2 0.0625 0.0625 0.10579 0.10056 0.00522933 19 3 2 0.125 0.0625 0.203545 0.199658 0.00388708 20 4 2 0.1875 0.0625 0.299951 0.295886 0.00406452 21 5 2 0.25 0.0625 0.391603 0.38795 0.00365301 22 6 2 0.3125 0.0625 0.477924 0.474712 0.00321207 23 7 2 0.375 0.0625 0.55786 0.55524 0.00261959 24 8 2 0.4375 0.0625 0.630775 0.628842 0.00193347 25 9 2 0.5 0.0625 0.696262 0.69509 0.00117132 26 10 2 0.5625 0.0625 0.754206 0.753842 0.000364567 27 11 2 0.625 0.0625 0.804784 0.80524 0.000456313 28 12 2 0.6875 0.0625 0.848452 0.849712 0.0012595 29 13 2 0.75 0.0625 0.885935 0.88795 0.00201456 30 14 2 0.8125 0.0625 0.91819 0.920886 0.00269655 31 15 2 0.875 0.0625 0.946453 0.949658 0.00320434 32 16 2 0.9375 0.0625 0.971294 0.97556 0.00426653 33 17 2 1 0.0625 1 1 0 34 1 3 0 0.125 0 0 0 35 2 3 0.0625 0.125 0.141045 0.137158 0.00388708 36 3 3 0.125 0.125 0.274772 0.271447 0.00332555 37 4 3 0.1875 0.125 0.403832 0.400108 0.0037244 38 5 3 0.25 0.125 0.524307 0.520598 0.00370845 39 6 3 0.3125 0.125 0.634306 0.63069 0.00361675 40 7 3 0.375 0.125 0.731923 0.728553 0.00336996 41 8 3 0.4375 0.125 0.815828 0.81283 0.00299745 42 9 3 0.5 0.125 0.885192 0.882683 0.00250889 43 10 3 0.5625 0.125 0.939754 0.93783 0.00192411 44 11 3 0.625 0.125 0.979819 0.978553 0.00126534 45 12 3 0.6875 0.125 1.00625 1.00569 0.000557444 46 13 3 0.75 0.125 1.02043 1.0206 0.00016549 47 14 3 0.8125 0.125 1.02417 1.02511 0.000932687 48 15 3 0.875 0.125 1.02009 1.02145 0.001355 49 16 3 0.9375 0.125 1.00895 1.01216 0.00320434 50 17 3 1 0.125 1 1 0 51 1 4 0 0.1875 0 0 0 52 2 4 0.0625 0.1875 0.174951 0.170886 0.00406452 53 3 4 0.125 0.1875 0.341332 0.337608 0.0037244 54 4 4 0.1875 0.1875 0.500453 0.496158 0.00429513 55 5 4 0.25 0.1875 0.647291 0.642847 0.00444373 56 6 4 0.3125 0.1875 0.778923 0.77444 0.00448298 57 7 4 0.375 0.1875 0.892616 0.88828 0.00433565 58 8 4 0.4375 0.1875 0.98642 0.982395 0.00402493 59 9 4 0.5 0.1875 1.05913 1.05557 0.00355884 60 10 4 0.5625 0.1875 1.11035 1.1074 0.00295607 61 11 4 0.625 0.1875 1.14052 1.13828 0.00224019 62 12 4 0.6875 0.1875 1.15087 1.14944 0.00143454 63 13 4 0.75 0.1875 1.14344 1.14285 0.00059487 64 14 4 0.8125 0.1875 1.12079 1.12116 0.000366704 65 15 4 0.875 0.1875 1.08667 1.08761 0.000932687 66 16 4 0.9375 0.1875 1.04319 1.04589 0.00269655 67 17 4 1 0.1875 1 1 0 68 1 5 0 0.25 0 0 0 69 2 5 0.0625 0.25 0.204103 0.20045 0.00365301 70 3 5 0.125 0.25 0.399307 0.395598 0.00370845 71 4 5 0.1875 0.25 0.584791 0.580347 0.00444373 72 5 5 0.25 0.25 0.754818 0.75 0.00481787 73 6 5 0.3125 0.25 0.905487 0.900438 0.00504935 74 7 5 0.375 0.25 1.03336 1.02828 0.0050778 75 8 5 0.4375 0.25 1.13593 1.13102 0.00491285 76 9 5 0.5 0.25 1.21167 1.20711 0.00455886 77 10 5 0.5625 0.25 1.26005 1.25602 0.00402943 78 11 5 0.625 0.25 1.28163 1.27828 0.00334663 79 12 5 0.6875 0.25 1.27797 1.27544 0.00252838 80 13 5 0.75 0.25 1.25164 1.25 0.00164007 81 14 5 0.8125 0.25 1.20594 1.20535 0.00059487 82 15 5 0.875 0.25 1.14543 1.1456 0.00016549 83 16 5 0.9375 0.25 1.07344 1.07545 0.00201456 84 17 5 1 0.25 1 1 0 85 1 6 0 0.3125 0 0 0 86 2 6 0.0625 0.3125 0.227924 0.224712 0.00321207 87 3 6 0.125 0.3125 0.446806 0.44319 0.00361675 88 4 6 0.1875 0.3125 0.653923 0.64944 0.00448298 89 5 6 0.25 0.3125 0.842987 0.837938 0.00504935 90 6 6 0.3125 0.3125 1.00929 1.00384 0.00544661 91 7 6 0.375 0.3125 1.14881 1.14318 0.00563042 92 8 6 0.4375 0.3125 1.25859 1.25299 0.00559825 93 9 6 0.5 0.3125 1.33682 1.33147 0.00535113 94 10 6 0.5625 0.3125 1.38289 1.37799 0.00489781 95 11 6 0.625 0.3125 1.39744 1.39318 0.00425823 96 12 6 0.6875 0.3125 1.38229 1.37884 0.00344814 97 13 6 0.75 0.3125 1.34047 1.33794 0.00252838 98 14 6 0.8125 0.3125 1.27587 1.27444 0.00143454 99 15 6 0.875 0.3125 1.19375 1.19319 0.000557444 100 16 6 0.9375 0.3125 1.09845 1.09971 0.0012595 101 17 6 1 0.3125 1 1 0 102 1 7 0 0.375 0 0 0 103 2 7 0.0625 0.375 0.24536 0.24274 0.00261959 104 3 7 0.125 0.375 0.481923 0.478553 0.00336996 105 4 7 0.1875 0.375 0.705116 0.70078 0.00433565 106 5 7 0.25 0.375 0.908359 0.903281 0.0050778 107 6 7 0.3125 0.375 1.08631 1.08068 0.00563042 108 7 7 0.375 0.375 1.23452 1.22855 0.00596777 109 8 7 0.4375 0.375 1.3497 1.34363 0.00607475 110 9 7 0.5 0.375 1.42983 1.42388 0.00594887 111 10 7 0.5625 0.375 1.47422 1.46863 0.00559372 112 11 7 0.625 0.375 1.48358 1.47855 0.00502533 113 12 7 0.6875 0.375 1.45994 1.45568 0.00425823 114 13 7 0.75 0.375 1.40663 1.40328 0.00334663 115 14 7 0.8125 0.375 1.32802 1.32578 0.00224019 116 15 7 0.875 0.375 1.22982 1.22855 0.00126534 117 16 7 0.9375 0.375 1.11728 1.11774 0.000456313 118 17 7 1 0.375 1 1 0 119 1 8 0 0.4375 0 0 0 120 2 8 0.0625 0.4375 0.255775 0.253842 0.00193347 121 3 8 0.125 0.4375 0.503328 0.50033 0.00299745 122 4 8 0.1875 0.4375 0.73642 0.732395 0.00402493 123 5 8 0.25 0.4375 0.948433 0.94352 0.00491285 124 6 8 0.3125 0.4375 1.13359 1.12799 0.00559825 125 7 8 0.375 0.4375 1.2872 1.28113 0.00607475 126 8 8 0.4375 0.4375 1.40576 1.39944 0.00631544 127 9 8 0.5 0.4375 1.4871 1.48079 0.00631436 128 10 8 0.5625 0.4375 1.53051 1.52444 0.00606995 129 11 8 0.625 0.4375 1.53672 1.53113 0.00559372 130 12 8 0.6875 0.4375 1.50789 1.50299 0.00489781 131 13 8 0.75 0.4375 1.44755 1.44352 0.00402943 132 14 8 0.8125 0.4375 1.36035 1.3574 0.00295607 133 15 8 0.875 0.4375 1.25225 1.25033 0.00192411 134 16 8 0.9375 0.4375 1.12921 1.12884 0.000364567 135 17 8 1 0.4375 1 1 0 136 1 9 0 0.5 0 0 0 137 2 9 0.0625 0.5 0.258762 0.25759 0.00117132 138 3 9 0.125 0.5 0.510192 0.507683 0.00250889 139 4 9 0.1875 0.5 0.746629 0.74307 0.00355884 140 5 9 0.25 0.5 0.961666 0.957107 0.00455886 141 6 9 0.3125 0.5 1.14932 1.14397 0.00535113 142 7 9 0.375 0.5 1.30483 1.29888 0.00594887 143 8 9 0.4375 0.5 1.4246 1.41829 0.00631436 144 9 9 0.5 0.5 1.50644 1.5 0.0064384 145 10 9 0.5625 0.5 1.5496 1.54329 0.00631436 146 11 9 0.625 0.5 1.55483 1.54888 0.00594887 147 12 9 0.6875 0.5 1.52432 1.51897 0.00535113 148 13 9 0.75 0.5 1.46167 1.45711 0.00455886 149 14 9 0.8125 0.5 1.37163 1.36807 0.00355884 150 15 9 0.875 0.5 1.26019 1.25768 0.00250889 151 16 9 0.9375 0.5 1.13376 1.13259 0.00117132 152 17 9 1 0.5 1 1 0 153 1 10 0 0.5625 0 0 0 154 2 10 0.0625 0.5625 0.254206 0.253842 0.000364567 155 3 10 0.125 0.5625 0.502254 0.50033 0.00192411 156 4 10 0.1875 0.5625 0.735351 0.732395 0.00295607 157 5 10 0.25 0.5625 0.947549 0.94352 0.00402943 158 6 10 0.3125 0.5625 1.13289 1.12799 0.00489781 159 7 10 0.375 0.5625 1.28672 1.28113 0.00559372 160 8 10 0.4375 0.5625 1.40551 1.39944 0.00606995 161 9 10 0.5 0.5625 1.4871 1.48079 0.00631436 162 10 10 0.5625 0.5625 1.53076 1.52444 0.00631544 163 11 10 0.625 0.5625 1.5372 1.53113 0.00607475 164 12 10 0.6875 0.5625 1.50859 1.50299 0.00559825 165 13 10 0.75 0.5625 1.44843 1.44352 0.00491285 166 14 10 0.8125 0.5625 1.36142 1.3574 0.00402493 167 15 10 0.875 0.5625 1.25333 1.25033 0.00299745 168 16 10 0.9375 0.5625 1.13078 1.12884 0.00193347 169 17 10 1 0.5625 1 1 0 170 1 11 0 0.625 0 0 0 171 2 11 0.0625 0.625 0.242284 0.24274 0.000456313 172 3 11 0.125 0.625 0.479819 0.478553 0.00126534 173 4 11 0.1875 0.625 0.70302 0.70078 0.00224019 174 5 11 0.25 0.625 0.906628 0.903281 0.00334663 175 6 11 0.3125 0.625 1.08494 1.08068 0.00425823 176 7 11 0.375 0.625 1.23358 1.22855 0.00502533 177 8 11 0.4375 0.625 1.34922 1.34363 0.00559372 178 9 11 0.5 0.625 1.42983 1.42388 0.00594887 179 10 11 0.5625 0.625 1.4747 1.46863 0.00607475 180 11 11 0.625 0.625 1.48452 1.47855 0.00596777 181 12 11 0.6875 0.625 1.46131 1.45568 0.00563042 182 13 11 0.75 0.625 1.40836 1.40328 0.0050778 183 14 11 0.8125 0.625 1.33012 1.32578 0.00433565 184 15 11 0.875 0.625 1.23192 1.22855 0.00336996 185 16 11 0.9375 0.625 1.12036 1.11774 0.00261959 186 17 11 1 0.625 1 1 0 187 1 12 0 0.6875 0 0 0 188 2 12 0.0625 0.6875 0.223452 0.224712 0.0012595 189 3 12 0.125 0.6875 0.443747 0.44319 0.000557444 190 4 12 0.1875 0.6875 0.650874 0.64944 0.00143454 191 5 12 0.25 0.6875 0.840466 0.837938 0.00252838 192 6 12 0.3125 0.6875 1.00729 1.00384 0.00344814 193 7 12 0.375 0.6875 1.14744 1.14318 0.00425823 194 8 12 0.4375 0.6875 1.25789 1.25299 0.00489781 195 9 12 0.5 0.6875 1.33682 1.33147 0.00535113 196 10 12 0.5625 0.6875 1.38359 1.37799 0.00559825 197 11 12 0.625 0.6875 1.39881 1.39318 0.00563042 198 12 12 0.6875 0.6875 1.38429 1.37884 0.00544661 199 13 12 0.75 0.6875 1.34299 1.33794 0.00504935 200 14 12 0.8125 0.6875 1.27892 1.27444 0.00448298 201 15 12 0.875 0.6875 1.19681 1.19319 0.00361675 202 16 12 0.9375 0.6875 1.10292 1.09971 0.00321207 203 17 12 1 0.6875 1 1 0 204 1 13 0 0.75 0 0 0 205 2 13 0.0625 0.75 0.198435 0.20045 0.00201456 206 3 13 0.125 0.75 0.395433 0.395598 0.00016549 207 4 13 0.1875 0.75 0.580942 0.580347 0.00059487 208 5 13 0.25 0.75 0.75164 0.75 0.00164007 209 6 13 0.3125 0.75 0.902966 0.900438 0.00252838 210 7 13 0.375 0.75 1.03163 1.02828 0.00334663 211 8 13 0.4375 0.75 1.13505 1.13102 0.00402943 212 9 13 0.5 0.75 1.21167 1.20711 0.00455886 213 10 13 0.5625 0.75 1.26093 1.25602 0.00491285 214 11 13 0.625 0.75 1.28336 1.27828 0.0050778 215 12 13 0.6875 0.75 1.28049 1.27544 0.00504935 216 13 13 0.75 0.75 1.25482 1.25 0.00481787 217 14 13 0.8125 0.75 1.20979 1.20535 0.00444373 218 15 13 0.875 0.75 1.14931 1.1456 0.00370845 219 16 13 0.9375 0.75 1.0791 1.07545 0.00365301 220 17 13 1 0.75 1 1 0 221 1 14 0 0.8125 0 0 0 222 2 14 0.0625 0.8125 0.16819 0.170886 0.00269655 223 3 14 0.125 0.8125 0.336675 0.337608 0.000932687 224 4 14 0.1875 0.8125 0.495792 0.496158 0.000366704 225 5 14 0.25 0.8125 0.643442 0.642847 0.00059487 226 6 14 0.3125 0.8125 0.775874 0.77444 0.00143454 227 7 14 0.375 0.8125 0.89052 0.88828 0.00224019 228 8 14 0.4375 0.8125 0.985351 0.982395 0.00295607 229 9 14 0.5 0.8125 1.05913 1.05557 0.00355884 230 10 14 0.5625 0.8125 1.11142 1.1074 0.00402493 231 11 14 0.625 0.8125 1.14262 1.13828 0.00433565 232 12 14 0.6875 0.8125 1.15392 1.14944 0.00448298 233 13 14 0.75 0.8125 1.14729 1.14285 0.00444373 234 14 14 0.8125 0.8125 1.12545 1.12116 0.00429513 235 15 14 0.875 0.8125 1.09133 1.08761 0.0037244 236 16 14 0.9375 0.8125 1.04995 1.04589 0.00406452 237 17 14 1 0.8125 1 1 0 238 1 15 0 0.875 0 0 0 239 2 15 0.0625 0.875 0.133953 0.137158 0.00320434 240 3 15 0.125 0.875 0.270092 0.271447 0.001355 241 4 15 0.1875 0.875 0.399175 0.400108 0.000932687 242 5 15 0.25 0.875 0.520433 0.520598 0.00016549 243 6 15 0.3125 0.875 0.631247 0.63069 0.000557444 244 7 15 0.375 0.875 0.729819 0.728553 0.00126534 245 8 15 0.4375 0.875 0.814754 0.81283 0.00192411 246 9 15 0.5 0.875 0.885192 0.882683 0.00250889 247 10 15 0.5625 0.875 0.940828 0.93783 0.00299745 248 11 15 0.625 0.875 0.981923 0.978553 0.00336996 249 12 15 0.6875 0.875 1.00931 1.00569 0.00361675 250 13 15 0.75 0.875 1.02431 1.0206 0.00370845 251 14 15 0.8125 0.875 1.02883 1.02511 0.0037244 252 15 15 0.875 0.875 1.02477 1.02145 0.00332555 253 16 15 0.9375 0.875 1.01604 1.01216 0.00388708 254 17 15 1 0.875 1 1 0 255 1 16 0 0.9375 0 0 0 256 2 16 0.0625 0.9375 0.0962937 0.10056 0.00426653 257 3 16 0.125 0.9375 0.196453 0.199658 0.00320434 258 4 16 0.1875 0.9375 0.29319 0.295886 0.00269655 259 5 16 0.25 0.9375 0.385935 0.38795 0.00201456 260 6 16 0.3125 0.9375 0.473452 0.474712 0.0012595 261 7 16 0.375 0.9375 0.554784 0.55524 0.000456313 262 8 16 0.4375 0.9375 0.629206 0.628842 0.000364567 263 9 16 0.5 0.9375 0.696262 0.69509 0.00117132 264 10 16 0.5625 0.9375 0.755775 0.753842 0.00193347 265 11 16 0.625 0.9375 0.80786 0.80524 0.00261959 266 12 16 0.6875 0.9375 0.852924 0.849712 0.00321207 267 13 16 0.75 0.9375 0.891603 0.88795 0.00365301 268 14 16 0.8125 0.9375 0.924951 0.920886 0.00406452 269 15 16 0.875 0.9375 0.953545 0.949658 0.00388708 270 16 16 0.9375 0.9375 0.98079 0.97556 0.00522933 271 17 16 1 0.9375 1 1 0 272 1 17 0 1 0 0 0 273 2 17 0.0625 1 0.0625 0.0625 0 274 3 17 0.125 1 0.125 0.125 0 275 4 17 0.1875 1 0.1875 0.1875 0 276 5 17 0.25 1 0.25 0.25 0 277 6 17 0.3125 1 0.3125 0.3125 0 278 7 17 0.375 1 0.375 0.375 0 279 8 17 0.4375 1 0.4375 0.4375 0 280 9 17 0.5 1 0.5 0.5 0 281 10 17 0.5625 1 0.5625 0.5625 0 282 11 17 0.625 1 0.625 0.625 0 283 12 17 0.6875 1 0.6875 0.6875 0 284 13 17 0.75 1 0.75 0.75 0 285 14 17 0.8125 1 0.8125 0.8125 0 286 15 17 0.875 1 0.875 0.875 0 287 16 17 0.9375 1 0.9375 0.9375 0 288 17 17 1 1 1 1 0 ||U|| = 0.996235 ||W|| = 0.994293 ||U-W|| = 0.0623472 FEM2D_LEASTSQUARES: Normal end of execution.