Integrate a spline function squared

10 ビュー (過去 30 日間)
Ben Johannesson
Ben Johannesson 2015 年 11 月 22 日
編集済み: John D'Errico 2015 年 11 月 23 日
I used spline to find an piecewise polynomial for a function. I need to integrate that function squared. How can I do this in Matlab?

採用された回答

John D'Errico
John D'Errico 2015 年 11 月 23 日
編集済み: John D'Errico 2015 年 11 月 23 日
Not that hard to do.
x = linspace(0,2*pi,10);
y = cos(x);
spl = spline(x,y);
cnew = zeros(9,7);
for i = 1:9
cnew(i,:) = conv(spl.coefs(i,:),spl.coefs(i,:));
end
spl.coefs = cnew;
spl.order = 7;
splint = fnint(spl);
diff(fnval(splint,[0,2*pi]))
ans =
3.147
As a test, how well did we do?
syms u
int(cos(u)^2,[0,2*pi])
ans =
pi
Not too badly at all. I could easily have written the integrals of each segment directly, but as long as FNINT is there, why bother?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSplines についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by