フィルターのクリア

mean value of polynominal function

11 ビュー (過去 30 日間)
Christoph Thorwartl
Christoph Thorwartl 2020 年 7 月 24 日
Given is a polynomial function k. I would like to calculate the mean value of the function between two points (x1, x2).
This solution is too imprecise for my purpose.
mean = (polyval(k,x2) + polyvalk,x1))/2
I would be very grateful for any feedback.
  1 件のコメント
KSSV
KSSV 2020 年 7 月 24 日
Don't use the variable name as mean. It is an inbuilt function.

サインインしてコメントする。

採用された回答

KSSV
KSSV 2020 年 7 月 24 日
m = 1000 ;
x = linspace(x1,x2,m) ;
y = polyval(k,x) ;
iwant = mean(y) ;
  1 件のコメント
Christoph Thorwartl
Christoph Thorwartl 2020 年 7 月 24 日
Thank you!

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2020 年 7 月 24 日
編集済み: John D'Errico 2020 年 7 月 24 日
The average value of a function over some interval is just the definite integral of the function, then divided by the length of the interval. Goes back to basic calc.
Since you are talking about using polyval, then I assume the polynomial is in the form of coefficients, appropriate for polyval. As an example, consider the quadratic polynomial x^2 - x + 2, on the interval [1,3].
k = [1 -1 2];
x12 = [1 3];
format long g
>> diff(polyval(polyint(k),x12))/diff(x12)
ans =
4.33333333333333
If you want to verify the result:
syms x
K = x^2 - x + 2;
int(K,x12)/diff(x12)
ans =
13/3
They agree, as they should.
In both cases, this yields the exact result for that polynomial, not an approximation. Exact at least to within the limits of floating point arithmetic.
If you want a reference, this should do:
  2 件のコメント
Christoph Thorwartl
Christoph Thorwartl 2020 年 7 月 24 日
Thank you!
Christoph Thorwartl
Christoph Thorwartl 2020 年 7 月 24 日
This solution is perfect!

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by