필터 지우기
필터 지우기

Can i get arc length out of polyval?

조회 수: 3 (최근 30일)
Daniel Wurster
Daniel Wurster 2019년 5월 25일
댓글: John D'Errico 2019년 5월 25일
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?

채택된 답변

Star Strider
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
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
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 CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by