# 45 麦片

050

80主题 0最佳答案
 如下面代码，有一组三维的x,y,z坐标，如何将这些稀疏的点云拟合成曲面？ 如果用scatter3的命令，可以大体看出这个曲面的形状，近似于球面的一部分（事实上可以看做是在R=100的球面上铺了一层有略微凹凸（波动范围在1mm左右）的曲面）。我知道的是曲面拟合的方法很多，之前用的是下面这个方法： x=[];y=[];z=[]; [X,Y]=meshgrid(600:1:800,300:1/4:350); Z=griddata(x,y,z,X,Y); R=sqrt(x.^2+y.^2+z.^2); mesh(X,Y,Z) 但拟合出的曲面很乱，并不是要求的，scatter3点云的形状就是要求的曲面的大体形状，请问该怎么拟合呢 x=[639.2873168 644.3046228 648.3375158 653.2449638 658.2170898 662.8000238 667.6776638 672.3651138 676.8547815 681.224092 686.6601168 692.353259 697.5144502 702.0359877 706.0408531 711.2703777 715.3675729 720.6360916 725.5558191 729.5021933 733.6647225 738.131237 741.9481619 746.1455608 750.1872644 749.8476593 746.1133157 742.3558193 738.1437039 734.0444465 731.3684747 725.8856757 720.6539014 715.3453575 710.8758434 706.2711621 701.9531252 696.6200224 691.8083723 686.0741738 680.8478362 675.8739293 671.7326778 666.7113408 662.4051148 657.5278498 653.2534938 647.7535408 643.8927478 638.6994988 638.4787508 643.5342078 647.7422928 652.8598028 657.2465478 662.8057418 666.4866558 672.0535358 675.9488243 681.2377774 686.2664261 691.9184183 697.2954832 701.8544213 706.9780244 711.7201224 715.7776673 721.1218309 725.4435236 731.0167776 734.5232494 739.1253997 743.0820848 746.4597635 751.1238733 751.2299823 747.5820631 742.5538832 738.8483165 734.8475755 730.9429138 726.2244372 721.0436552 715.7122397 711.5503667 706.4988466 701.6074273 697.0439898 691.7287906 686.0693933 681.350448 676.3767286 671.3620468 665.7406128 661.1937658 656.4796948 652.1053228 647.7072358 643.8440988 638.1867638 637.3248618 643.4179758 648.3221428 651.9175698 656.8581068 661.5957058 667.1052188 671.7588308 676.4355947 681.2315909 686.382846 691.9166373 696.6538611 701.6809162 706.5028772 712.1025648 715.8319404 721.3496091 725.8203418 730.3849041 735.4405487 739.5935167 743.373041 747.7957809 751.6983805 751.7540596 748.1928461 742.9785067 734.5442462 725.7983139 729.9935568 738.8725003 721.270496 716.349175 711.868975 706.221857 701.222454 696.7677502 691.2980743 686.2742999 681.0014693 675.6741782 666.3712668 671.7852638 661.8036118 656.6816018 652.8268078 647.6554938 643.2518758 638.1562058 637.8111638 643.2957438 647.6631798 651.9000418 657.0378918 666.3723918 661.5627108 675.4642098 670.6882728 681.1566959 685.6476756 690.8966035 695.4375443 700.6550708 705.4477861 710.6459092 714.9488547 719.9341974 725.0165566 729.9255046 729.9060075 734.0668494 738.4426276 742.7528844 747.3845616 751.6556369 751.2560409 747.4915143 742.9193594 738.5631719 734.1601166 729.5395002 720.6720862 715.61063 710.6905275 705.2960278 701.3293129 696.1276279 685.5482218 680.7743473 676.1914128 672.1052788 665.8869338 661.6132338 656.5422168 652.5625668 647.1245728 643.9704548 638.1684848 638.1754218 643.8054798 647.1972188 652.5430698 656.5363118 662.0044878 666.4957488 671.8565968 676.1513875 680.966787 685.624429 705.7790487 700.6578828 695.9355631 691.1144456 691.1144456 710.6471278 715.9687948 719.918356 725.1645656 728.936966 733.8396336 738.4343788 742.6692721 745.9657754 751.4976919 750.4911561 746.7345033 742.933326 738.1074281 733.9978598 728.5514303 724.7930903 719.1731558 715.2863976 710.1723556 705.5196816 700.814703 695.4662275 690.2172059 685.8812654 680.9658497 675.8393408 672.3563028 666.2899978 662.5156298 657.5348798 651.7751848 648.0492778 643.8483168 638.6294778 640.0806028 644.0052308 648.2622458 652.7544438 658.0958888 663.0798258 666.7724568 672.6080778 676.5818226 681.2637423 685.8710481 690.7993056 695.0376671 715.3851952 710.2560617 705.4961539 699.9491459 715.5066769 719.46055 723.7183147 727.965956 733.7203078 737.6257194 741.2162722 745.8973482 750.6133877 750.0142279 745.3394323 740.4526998 736.7642867 732.9983541 727.3166476 723.3415903 718.2750723 714.8953315 709.9504828 704.6505625 699.360672 694.5164019 690.2349219 685.6562055 681.079645 676.169666 671.9834218 667.1183418 662.7543748 657.9781568 652.2275548 648.2091908 644.7646788 639.9628708 641.9517588 645.1831158 649.2785298 653.1453228 658.3188868 663.6637068 668.0632938 673.0017688 676.2208458 681.4341541 685.5481281 690.4857591 694.83576 699.1167713 704.4474369 713.3543137 709.5555735 717.9541207 722.1415836 726.3918494 731.7308576 739.8281376 744.8821886 748.6326548 747.4573007 743.2459352 738.7135243 734.6361073 731.0318691 726.0713665 721.6681236 716.8790639 713.2342381 708.7825338 704.2459985 699.4271308 694.7227145 690.0153925 685.9455682 681.294019 677.2160396 672.6502588 667.7384048 664.1155138 658.6819258 653.6036908 650.1711768 646.1242238 641.9192328]; y=[327.4984558 324.5646318 322.6728648 320.5214508 318.9726608 317.6378688 316.1188868 315.1487258 314.6492098 314.1656288 313.8155278 313.6615208 313.8455228 314.2668638 314.8778308 315.9403208 316.9462888 318.6233088 320.4166538 322.0304958 323.6736778 326.1253268 328.3372938 331.3916608 334.1577918 331.6678058 329.2676178 326.7621648 324.5327628 322.3545398 321.0667088 318.7678488 316.8724258 315.3615988 314.4202148 313.5745338 312.9733158 312.5361328 312.3777208 312.5349148 312.9418198 313.4322438 314.0756438 315.1326038 316.2955788 317.8003118 319.3312918 321.6734578 323.3474788 326.4730848 325.0775528 322.1034228 319.8995158 317.9664118 316.3336348 314.4721438 313.5199798 312.2076848 311.6530528 311.1136988 310.8272438 310.6578638 310.8244318 311.5530368 312.2695498 313.1530058 314.1342278 315.6962348 317.1920638 319.5361038 321.1279178 323.6166868 325.7110158 327.9719138 331.4068458 330.0677428 327.3407928 323.9899408 321.7825658 319.6914238 318.0163728 316.1832838 314.3880628 312.8772368 311.8648008 310.9373828 310.3968108 310.0193388 309.8380538 309.9175418 310.2779548 310.7927488 311.6036538 312.8523968 314.3008898 315.7004518 317.3734418 319.1865648 320.9308868 324.1752558 323.9319188 320.4627718 318.0548978 316.6072488 314.6977648 313.0731438 311.5143238 310.4479908 309.6359608 309.2167758 308.8706118 308.7709708 308.9045438 309.3282278 309.9522238 311.0044038 311.8858908 313.6705188 315.1598808 316.9868768 319.2172158 321.2782698 323.5430098 326.5021428 329.3466358 328.5421058 325.9723498 322.5412608 317.9596628 314.3368838 315.9979688 320.2589908 312.8312118 311.4231198 310.3883748 309.3211038 308.7007628 308.3359448 308.1764068 308.2597378 308.6981378 309.3785638 311.3752208 310.0199948 312.6782358 314.4149658 315.7800338 318.0747698 320.2209348 322.9463848 322.9412288 319.8815188 317.7431338 315.8888608 313.8982958 310.9872498 312.4168078 308.9898428 309.9439758 308.2249618 307.8199318 307.6793288 307.7850618 308.1769698 308.7400378 309.6781418 310.6259938 311.9396008 313.5825018 315.5154188 315.5087638 317.3527258 319.5375098 321.9980638 324.9992838 328.0784908 327.4792398 324.7599768 321.8033758 319.3430088 317.1375098 315.0841418 311.9309778 310.5390078 309.4014348 308.4368978 307.9418808 307.5860618 307.6632998 308.1066678 308.7164168 309.4724868 310.9724398 312.1985918 313.9335408 315.4538348 317.8652708 319.3882828 322.6452128 322.7264818 319.4465868 317.7126698 315.4433358 313.9089818 312.0278998 310.6962018 309.4002168 308.6006538 307.9999968 307.6249618 308.3647218 307.7814998 307.4828588 307.3954978 307.4570818 309.2415228 310.4867968 311.5963428 313.3021388 314.7361968 316.8069048 319.1311668 321.5660378 323.6623358 327.5956598 327.1487288 324.4615238 321.9555078 319.2099048 317.1154818 314.7124818 313.3107628 311.5204168 310.4249318 309.2552078 308.4605188 307.8939828 307.6035908 307.5383508 307.7419438 308.1173538 308.7283208 309.4217758 310.9043878 312.1079498 313.7875948 315.9406018 317.5469458 319.6933918 322.9074848 322.8560238 320.4835818 318.0362438 316.2131848 314.3183238 312.5426008 311.3204788 309.9119178 309.0982008 308.5771258 308.2732358 308.1106988 308.1131358 310.9795638 309.8005598 308.9975288 308.3154168 311.0252128 312.1143238 313.4718938 315.0264948 317.4886418 319.4888618 321.5198258 324.5396988 327.9171718 328.5905668 325.2685848 322.2045628 319.9275428 318.1047648 315.5140128 314.1577558 312.4739868 311.5388828 310.4284928 309.5556298 308.9665968 308.8676118 308.8140888 309.0248998 309.2946708 309.9715328 310.8105588 311.9949048 313.4608328 315.0664268 317.2436178 319.3435718 321.1740358 324.0459938 324.5666008 322.4099368 320.0247468 318.1195748 316.3090758 314.3348218 313.1036078 311.8570208 311.0963578 310.4415228 310.1597538 310.0245878 309.8745178 310.1321018 310.7402568 312.3813758 311.5671908 313.5057318 314.7833458 316.2875168 318.5152318 322.8901438 326.2511188 328.8941758 329.6518388 326.7839108 323.7737868 321.3691928 319.6334948 317.5765658 316.0782998 314.2954528 313.3746898 312.4630198 311.7502558 311.1993728 311.0393668 311.0138708 311.1495998 311.5730028 312.0899528 312.9894378 314.3097938 315.4588958 317.4862048 319.4194038 321.2421818 323.4905188 326.0776148]; z=[-1021.701065 -1021.922563 -1022.644423 -1022.920851 -1023.877332 -1024.601536 -1024.569759 -1024.821346 -1025.660001 -1025.656908 -1025.652503 -1025.616133 -1025.614071 -1025.611634 -1025.71943 -1026.027821 -1026.023697 -1026.355241 -1026.351772 -1026.349148 -1025.558954 -1025.558298 -1025.338487 -1025.732084 -1025.06206 -1019.632408 -1020.59695 -1020.592638 -1021.486223 -1021.482848 -1021.478911 -1021.476662 -1021.474693 -1021.475162 -1021.810924 -1021.809799 -1021.809612 -1021.80933 -1021.808112 -1021.808112 -1021.833983 -1021.784209 -1021.367272 -1020.920714 -1020.389794 -1019.647968 -1019.369291 -1019.000346 -1017.842614 -1017.845895 -1012.737757 -1012.741787 -1012.744318 -1013.873555 -1013.873555 -1014.217472 -1015.076936 -1015.077124 -1015.580579 -1015.580111 -1015.918216 -1015.919247 -1015.918778 -1017.048953 -1017.048858 -1017.079229 -1017.04989 -1017.160123 -1017.118504 -1017.118692 -1017.118504 -1017.118692 -1016.134652 -1016.137371 -1015.971833 -1011.084912 -1011.08688 -1011.088848 -1011.090911 -1011.202644 -1011.659888 -1012.10354 -1012.103165 -1012.103352 -1012.103352 -1012.102977 -1012.496762 -1012.498824 -1012.498262 -1012.130911 -1012.131567 -1012.133723 -1011.801335 -1011.019296 -1011.021452 -1009.563203 -1009.565078 -1009.06584 -1007.901172 -1007.902578 -1003.050339 -1003.038621 -1003.04059 -1003.995196 -1003.99454 -1004.500808 -1005.231479 -1005.513812 -1005.592737 -1006.326502 -1006.494289 -1006.841956 -1006.841768 -1006.842987 -1006.842706 -1006.842799 -1006.842893 -1008.022747 -1007.856834 -1007.856178 -1007.411589 -1006.626082 -1006.627019 -1006.6273 -1006.124501 -1000.362743 -1000.945686 -1001.16859 -1001.672514 -1002.340851 -1002.339821 -1002.341039 -1002.374596 -1002.375627 -1002.375252 -1002.352287 -1002.352381 -1002.352568 -1002.352381 -1002.018025 -1002.017931 -1001.963002 -1001.963939 -1001.46039 -1000.959278 -1000.511126 -999.0567197 -999.0876527 -999.0404097 -997.7516347 -992.5797567 -992.5375747 -992.5625087 -993.6337227 -994.0295697 -995.2574157 -995.2558227 -995.5113467 -995.5099407 -996.4051187 -996.4029627 -996.4547987 -997.0135587 -997.0109337 -997.0302437 -997.0283687 -997.0453347 -997.0450537 -997.0431787 -997.0608017 -997.0609887 -997.0264007 -997.0262127 -996.1450017 -996.1465007 -995.5300937 -990.9119127 -990.9117257 -990.9120077 -991.9763777 -991.9759097 -991.9754407 -992.6497767 -992.7033937 -992.7020817 -992.6784607 -992.4533067 -992.4507757 -992.3416677 -992.1743487 -992.1735987 -991.4435837 -991.4431147 -990.6012727 -990.2154557 -989.3713637 -988.9865777 -987.8677457 -987.2393407 -982.4564657 -982.4556227 -982.4556227 -983.6311637 -984.1345257 -985.3313467 -985.3290967 -986.2902647 -986.2882957 -986.2862337 -986.6253707 -987.0725847 -986.9245757 -986.9002037 -986.8986107 -992.1032967 -986.4398667 -987.1225457 -987.1229207 -987.1240457 -987.1239517 -986.7213557 -986.7227617 -986.6749567 -986.1189157 -986.1554727 -980.6188677 -980.6206487 -981.0645817 -981.0996387 -981.8338717 -982.2832417 -982.2836167 -982.2832417 -982.5594817 -982.5596687 -982.5605127 -982.5601377 -981.9672587 -982.7522967 -982.0828347 -982.0844277 -982.0848967 -981.0203387 -981.3020147 -980.4660777 -979.9818377 -979.4767887 -978.4583487 -978.4605977 -977.7299267 -972.6009787 -972.6287247 -973.9992377 -973.8613517 -973.8910667 -974.8466097 -975.6867647 -975.6878897 -976.6414657 -976.6442777 -976.6441837 -976.6446527 -976.6444647 -977.0484667 -977.0339377 -977.0344057 -977.0374057 -977.0386247 -977.0387177 -977.0387177 -977.0155657 -977.0158467 -976.5650707 -976.3891277 -975.8896097 -975.8361807 -970.5107627 -970.5110437 -970.5108557 -971.6923967 -971.6926777 -972.4789347 -972.1763557 -972.7309907 -972.7311787 -972.7308977 -972.7307097 -972.7307097 -971.9632937 -972.3225837 -972.1614517 -972.1623887 -971.6657757 -971.1274507 -971.1521967 -970.2384597 -970.0722657 -969.5701227 -967.8151987 -967.8171667 -967.8183857 -961.9817317 -962.8231987 -963.6644787 -964.5061337 -964.2838857 -965.2334307 -965.2326807 -965.7152337 -966.3797267 -966.3780397 -966.5451707 -966.5451707 -967.1058987 -967.1060867 -967.1055247 -967.1054307 -967.1051497 -967.5691417 -967.5695167 -967.5693297 -967.5694227 -966.7377987 -965.7297617 -965.7589137 -960.8937397 -960.8922397 -961.6735287 -962.3960447 -962.3937957 -962.3917327 -962.0547527 -963.2344187 -963.1219357 -963.0666317 -963.0474157 -962.9239657 -962.5792047 -962.6331027 -962.6332907 -962.2498167 -962.1019017 -961.8156317 -961.1796337 -960.6705537 -959.7000127 -959.6999187 -958.6887897 -958.1819597 -957.7880817];

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-13 22:28:46 | 显示全部楼层
 自己支持一下，是否要用最小二乘法拟合必须给出函数形式呢？

# 论坛优秀回答者

15主题 117最佳答案
• 关注者： 159

 SSy =      12821 fx=@(b,x,z)(b(1)+b(2)*z+b(3)*x.^2+b(4)*z.^2+b(5)*x.*z)./(1+b(6)*x+b(7)*z+b(8)*x.*z); b =[-170.2810544  -0.2958026298  -0.0003555290089  -0.0003287562198  -0.0005108451592  -0.001532204202  0.001106913274  -1.592865228e-06] RSS = 13.9728587681 MSe =  0.040976 R^2 =   0.99891

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-14 09:58:11 | 显示全部楼层
 stats01 发表于 2018-5-14 09:31 SSy =      12821 fx=@(b,x,z)(b(1)+b(2)*z+b(3)*x.^2+b(4)*z.^2+b(5)*x.*z)./(1+b(6)*x+b(7)*z+b(8)*x.*z) ... 1.SSy是什么呢？ 2.b,RSS,MSe,R^2应该是求得的解把 3.能否给一下完整程序，这个图我怎么用mesh绘制不出来？

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-14 10:39:00 | 显示全部楼层
 stats01 发表于 2018-5-14 09:31 SSy =      12821 fx=@(b,x,z)(b(1)+b(2)*z+b(3)*x.^2+b(4)*z.^2+b(5)*x.*z)./(1+b(6)*x+b(7)*z+b(8)*x.*z) ... fx=@(b,x,z)(b(1)+b(2)*z+b(3)*x.^2+b(4)*z.^2+b(5)*x.*z)./(1+b(6)*x+b(7)*z+b(8)*x.*z); 这个模型是根据什么建立的呢？

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-14 15:49:15 | 显示全部楼层
 stats01 发表于 2018-5-14 09:31 SSy =      12821 fx=@(b,x,z)(b(1)+b(2)*z+b(3)*x.^2+b(4)*z.^2+b(5)*x.*z)./(1+b(6)*x+b(7)*z+b(8)*x.*z) ... 版主可以解决一下疑惑吗？

# 论坛优秀回答者

15主题 117最佳答案
• 关注者： 159

 本帖最后由 stats01 于 2018-5-14 17:28 编辑 绝不放过你 发表于 2018-5-14 15:49 版主可以解决一下疑惑吗？ clear,clc X=[...];%输入数据（以列方式输入）; x1=X(:,1);x2=X(:,3);y=X(:,2);X(:,2)=[]; fx1=@(b,x,y)(b(1)+b(2)*y+b(3)*x.^2+b(4)*y.^2+b(5)*x.*y)./(1+b(6)*x+b(7)*y+b(8)*x.*y); fx2=@(b,X,y)(b(1)+b(2)*X(:,2)+b(3)*X(:,1).^2+b(4)*X(:,2).^2+b(5)*X(:,1).*X(:,2))./(1+b(6)*X(:,1)+b(7)*X(:,2)+b(8)*X(:,1).*X(:,2)); b=[-170.2810544  -0.2958026298  -0.0003555290089  -0.0003287562198  -0.0005108451592  -0.001532204202  0.001106913274  -1.592865228e-06]; for l=1:5     b=lsqcurvefit(fx2,b,X,y);     b=nlinfit(X,y,fx2,b); end b r1=range(x1);r2=range(x2); [x11,x22]=meshgrid(min(x1)-r1/20:r1/60:max(x1)+r1/20,min(x2)-r2/20:r2/60:max(x2)+r2/20); figure(1),clf plot3(x1,x2,y,'o','markerfacecolor','k') yhat=fx1(b,x11,x22); hold on surf(x11,x22,yhat); shading interp alpha(.8) xlabel('X'),ylabel('Z'),zlabel('Y') axis tight n=length(y); y1=fx1(b,x1,x2); RSS=(y-y1)'*(y-y1) SSy=var(y)*(n-1) MSe=RSS/(n-length(b)) Rsquare=(SSy-RSS)/SSy

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-14 17:19:27 | 显示全部楼层
 stats01 发表于 2018-5-14 17:09 clear,clc X=[...];%输入数据（以列方式输入）; x1=X(:,1);x2=X(:,2);y=X(:,2);X(:,2)=[]; 我得到的是下面的图为什么？

# 论坛优秀回答者

15主题 117最佳答案
• 关注者： 159

 本帖最后由 stats01 于 2018-5-14 17:30 编辑 绝不放过你 发表于 2018-5-14 17:19 我得到的是下面的图为什么？ 上面第3行我改了一下。

# 45 麦片

050

80主题 0最佳答案
楼主| 发表于 2018-5-14 19:08:24 | 显示全部楼层
 stats01 发表于 2018-5-14 17:29 上面第3行我改了一下。 应该怎么修改才能绘制出原来的图呢？
 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页