フィルターのクリア

How do you calculate the average value of a line?

2 ビュー (過去 30 日間)
Colin Lynch
Colin Lynch 2017 年 12 月 22 日
コメント済み: Colin Lynch 2017 年 12 月 23 日
I am attempting to calculate the average value of a line using the equation from this website: http://tutorial.math.lamar.edu/Classes/CalcI/AvgFcnValue.aspx
Part of this equation requires getting a definite integral from x0 to x1. I only want the positive values of these lines, and the maximum value of the y coordinate is 1. To accomplish this, I want the lower of limit of x to be where this line crosses the x-axis (x0), and I want the upper limit of x to be where y = 1 (x1). I tried to do this with the following code:
fun = @(x,c) sqrt((-.25 .*(n-(c.*n))./(100-n))./(((n-(c.*n))./(100-n))-1));
x0 = fzero(@(x)fun(x,.5), 1);
x1 = fzero(@(x)fun(x,.5)-1, 1);
q = (1/(x1-x0))*integral(@(x)fun(x,.5),x0, x1)
This code, however, spits out some strange errors that I do not know how to resolve. How can I fix this so that I can find the average value of this line?
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 23 日
The first obvious problem is that n is not defined.
Ahmed raafat
Ahmed raafat 2017 年 12 月 23 日
fun = @(x,c) sqrt((-.25 .*(n-(c.*n))./(100-n))./(((n-(c.*n))./(100-n))-1));
it is fun of n & c not x & c

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 23 日
x0 = fzero(@(x)fun(x,.5), [0 66.66666666]);
x1 = fzero(@(x)fun(x,.5)-1, [0 66.66666666]);
fun(x,1/2) has a discontinuity at 200/3 but grows fairly slowly, so it is necessary to get fairly close to 200/3 to satisfy x1
  4 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 23 日
The discontinuity is at 100/(2 - c) . But you have to make sure you do not use exactly that number or else you will get inf there. So like 100/(2-c) * (1-10*eps)
Colin Lynch
Colin Lynch 2017 年 12 月 23 日
Thank you again!

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

その他の回答 (1 件)

Ahmed raafat
Ahmed raafat 2017 年 12 月 23 日
where is x????
fun = @(x,c) sqrt((-.25 .*(n-(c.*n))./(100-n))./(((n-(c.*n))./(100-n))-1));
  1 件のコメント
Colin Lynch
Colin Lynch 2017 年 12 月 23 日
編集済み: Colin Lynch 2017 年 12 月 23 日
Whoops, that was an obvious mistake. Still, even if n is replaced with x, the problem persists

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by