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?

采纳的回答

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