Can i get arc length out of polyval?
3 ビュー (過去 30 日間)
古いコメントを表示
Hello, i would like to know if i can get the arc lenght out of a polyval.
I work on the following steps:
1) Have data (vector) x and y(x)
2) fit a function between both data -> here polyval
3) now i want to calcuculate the arc lenght
I got a bigger project, but a simple function with the three steps would be like:
% 1) based on
x = 1:10;
y = 2+x.^2.;
% 2) fit
p = polyfit(x,y,3);
% create a function handle for the integral
f = @(arg) polyval(p,arg);
%now the function for the arc length
r = sqrt(1+(diff(f)).^2.);
b = integral(r,0,10);
%plot it
xpl = 1:0.01:10;
plot(x,y,'r+',xpl,f(xpl));
Error report i get:
/* Undefined function 'diff' for input arguments of type 'function_handle'.
Error in asdfasdf (line 12)
r = sqrt(1+(diff(f)).^2.); */
-> What can i do to solve the error report?
0 件のコメント
採用された回答
Star Strider
2019 年 5 月 25 日
Try this (lightly edited version of your code):
dfdx = @(f,x) (f(x + 1E-8) - f(x)) ./ 1E-8; % Simple Numeric Derivative
% 1) based on
x = 1:10;
y = 2+x.^2.;
% 2) fit
p = polyfit(x,y,3);
% create a function handle for the integral
f = @(arg) polyval(p,arg);
%now the function for the arc length
r = @(x) sqrt(1+(dfdx(f,x)).^2.);
b = integral(r,0,10);
3 件のコメント
Star Strider
2019 年 5 月 25 日
As always, my pleasure!
That is a simple numerical differentiation function. It takes function handle ‘f’ and independent variable ‘x’ as arguments, and returns the numerical derivative of ‘f’ at ‘x’.
Numerical differentiation functions can get much more elaborate. See for example the Wikipedia article on Numerical differentiation (link).
John D'Errico
2019 年 5 月 25 日
I might note that the line in question is just a numerical derivative. However, you can compute the analytical derivative simply enough, since it ia a polynomial.
polyder does that for you, already a part of MATLAB.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!