複数の多項式近似

10 views (last 30 days)
とう
とう on 10 Dec 2022
Commented: とう on 12 Dec 2022
上の写真のように、ある物質の5秒間の温度変化を数字で表したCSVファイルがあります。例えば、0秒の時の温度はfile_0に入っており、1秒後の温度はfile_1に入っています。合計で172800点あるのですが、これら全ての点を2次の多項式近似として書き出す方法はあるでしょうか?
つまり172800点全ての点の5秒間の温度変化を数式で表すことが出来るかということです。
もし書き出せたら、y=2x²+3x+5のような式が172800個できるということになります。

Answers (1)

Atsushi Ueno
Atsushi Ueno on 10 Dec 2022
polyfit 関数を使い、2次多項式 の係数 を求めました。
係数は降べきの順、長さは 3 で () が 360*480=172800 組あります。
d(:,:,1) = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1226132/file_0.CSV');
d(:,:,2) = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1226137/file_1.CSV');
d(:,:,3) = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1226142/file_2.CSV');
d(:,:,4) = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1226147/file_3.CSV');
d(:,:,5) = readmatrix('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1226152/file_4.CSV');
[X,Y,Z] = size(d) % x,y 軸の項目も含む為、縦横1ずつサイズが大きい
X = 361
Y = 481
Z = 5
for x = 2:X
for y = 2:Y
p{x-1,y-1} = polyfit(0:4,d(x,y,:),2);
end
end
% 計算された係数を確認
size(p) % 係数の組が360*480=172800セット
ans = 1×2
360 480
p{1,1}
ans = 1×3
0.0043 0.6349 19.6386
p{360,480}(3) % f{x,y}(n)の形で個々の係数Pnを取り出せる
ans = 19.7369
  1 Comment
とう
とう on 12 Dec 2022
プログラミング本当にありがとうございます。
さらなる質問で恐縮なのですが、pの(1)の値だけを全てdoubleに変換することは可能でしょうか?

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!