Filter löschen
Filter löschen

指定した関数にデータ​をフィッティングさせ​,その際の係数を抽出

4 Ansichten (letzte 30 Tage)
泰誠 平山
泰誠 平山 am 15 Nov. 2023
Kommentiert: 泰誠 平山 am 29 Nov. 2023
下部に示すデータに以下の関数をフィッティングし,C1~C8の値を取り出したいです。これを実現するコードをご教授頂きたいです。
hc=[ 437.8721 441.0834 452.8841 436.7682 437.9955 448.4398 455.7468 443.8015 525.4903 538.895 537.2546 525.2589 516.5977 526.974 537.6951 531.9221 604.8993 609.551 602.9513 596.8787 601.4953 598.9064 606.6538 596.7564 668.5769 699.6305 678.4585 670.5805 680.9208 679.8531 673.3044 694.1689 756.6379 745.3489 750.0761 748.371 748.7925 752.3254 752.9984 759.1911 847.7004 842.3609 841.6435 836.3349 828.2203 838.1522 839.4045 838.6771 1203.12 1206.318 1197.958 1218.17 1223.971 1204.434 1217.797 1210.291 1543.912 1536.93 1542.479 1546.797 1544.828 1535.265 1530.165 1532.803 1818.71 1898.994 1869.862 1894.521 1875.092 1905.734 1891.786 1882.396 1901.279 1860.508 1949.379 1967.343 1884.619 1923.635 2025.482 2032.288 ]
A(hc)=[ 0.00047 0.000408 0.000467 0.00043 0.000388 0.00039 0.000353 0.000357 0.000531 0.000308 0.000402 0.000432 0.00039 0.000391 0.000371 0.000404 0.000372 0.000372 0.000353 0.000364 0.00039 0.000387 0.0004 0.000363 0.000298 0.000369 0.000301 0.000362 0.000344 0.000313 0.00029 0.00035 0.000324 0.000296 0.000278 0.000302 0.000299 0.00031 0.000277 0.000282 0.000185 0.00025 0.000243 0.000238 0.00024 0.000228 0.000272 0.000229 0.000132 0.000148 0.000149 9.87E-05 8.72E-05 0.000127 8.05E-05 8.99E-05 0.000128 0.000133 0.000127 0.000124 0.000116 0.000126 0.000128 0.000132 0.000159 8.88E-05 0.00011 7.62E-05 9.29E-05 5.55E-05 7.67E-05 9.71E-05 0.000139 0.000195 0.000112 0.000107 0.000206 0.000148 7.88E-05 8.1E-05 ]

Akzeptierte Antwort

VINAYAK LUHA
VINAYAK LUHA am 24 Nov. 2023
Hi 泰誠 平山,
私の母国語は日本語ではないので、この質問には英語で答えます。ご理解のほどよろしくお願いいたします。.
I understand that you want to fit the equation-"A" to the provided data in MATLAB and further want to find the values of the coefficients of the equation.
Follow the below steps to fit the curve to the given data:
  1. Define two arrays - "hc" and "Ahc" representing the variable values and its corresponding function values respectively.
  2. Next, Use the "fittype" function to define the equation and the independent parameter of the equation.
  3. Further, Use the "fit" function to perform the curve fitting the with initial guesses for the coefficients (c1-c8) as an array of zeros.
  4. Finally, extract the coefficients from the fitted model.
Here is the detailed code snippet for your reference-
hc = [437.8721, 441.0834, 452.8841, 436.7682, 437.9955, 448.4398, 455.7468, 443.8015, 525.4903, 538.895, 537.2546, 525.2589, 516.5977, 526.974, 537.6951, 531.9221, 604.8993, 609.551, 602.9513, 596.8787, 601.4953, 598.9064, 606.6538, 596.7564, 668.5769, 699.6305, 678.4585, 670.5805, 680.9208, 679.8531, 673.3044, 694.1689, 756.6379, 745.3489, 750.0761, 748.371, 748.7925, 752.3254, 752.9984, 759.1911, 847.7004, 842.3609, 841.6435, 836.3349, 828.2203, 838.1522, 839.4045, 838.6771, 1203.12, 1206.318, 1197.958, 1218.17, 1223.971, 1204.434, 1217.797, 1210.291, 1543.912, 1536.93, 1542.479, 1546.797, 1544.828, 1535.265, 1530.165, 1532.803, 1818.71, 1898.994, 1869.862, 1894.521, 1875.092, 1905.734, 1891.786, 1882.396, 1901.279, 1860.508, 1949.379, 1967.343, 1884.619, 1923.635, 2025.482, 2032.288];
A_hc = [0.00047, 0.000408, 0.000467, 0.00043, 0.000388, 0.00039, 0.000353, 0.000357, 0.000531, 0.000308, 0.000402, 0.000432, 0.00039, 0.000391, 0.000371, 0.000404, 0.000372, 0.000372, 0.000353, 0.000364, 0.00039, 0.000387, 0.0004, 0.000363, 0.000298, 0.000369, 0.000301, 0.000362, 0.000344, 0.000313, 0.00029, 0.00035, 0.000324, 0.000296, 0.000278, 0.000302, 0.000299, 0.00031, 0.000277, 0.000282, 0.000185, 0.00025, 0.000243, 0.000238, 0.00024, 0.000228, 0.000272, 0.000229, 0.000132, 0.000148, 0.000149, 9.87E-05, 8.72E-05, 0.000127, 8.05E-05, 8.99E-05, 0.000128, 0.000133, 0.000127, 0.000124, 0.000116, 0.000126, 0.000128, 0.000132, 0.000159, 8.88E-05, 0.00011, 7.62E-05, 9.29E-05, 5.55E-05, 7.67E-05, 9.71E-05, 0.000139, 0.000195, 0.000112, 0.000107, 0.000206, 0.000148, 7.88E-05, 8.1E-05];
fitFunction = fittype('24.5*x^2 + c1*x + c2*sqrt(x) + c3*x^(1/4) + c4*x^(1/8) + c5*x^(1/16) + c6*x^(1/32) + c7*x^(1/64) + c8*x^(1/128)', 'independent', 'x');
fittedModel = fit(hc', A_hc', fitFunction, 'StartPoint', [0, 0, 0, 0, 0, 0, 0, 0]);
c1 = fittedModel.c1;
c2 = fittedModel.c2;
c3 = fittedModel.c3;
c4 = fittedModel.c4;
c5 = fittedModel.c5;
c6 = fittedModel.c6;
c7 = fittedModel.c7;
c8 = fittedModel.c8;
Additionally, refer to the following documentations for more details on how to use the above mentioned functions-
  1. https://in.mathworks.com/help/curvefit/fittype.html
  2. https://in.mathworks.com/help/curvefit/fit.html
Hope this helps you in understanding how to perform curve fitting in MATLAB.
  1 Kommentar
泰誠 平山
泰誠 平山 am 29 Nov. 2023
Thank you for answering my question! I am sorry about the late reply. Fortunately I was able to solve a problem. I adapt your answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!