Integration of a derivative(arc length formula)
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adham Elkhouly
el 12 de Mayo de 2020
Comentada: haha mark
el 13 de Mayo de 2020
while (sz(1)-1 > 0)
x = linspace(points(z-1),points(z));
y = X^2+2*z;
dy = diff(y);
func= sqrt(1+dy.^2); %%arc length formula
I = I + integral(func,points(z-1),points(z)); %Error here
sz(1)=sz(1)-1;
z = z+1;
end
Error is
First input argument must be a function handle.
Can someone please help?
Thanks
0 comentarios
Respuesta aceptada
John D'Errico
el 12 de Mayo de 2020
Editada: John D'Errico
el 12 de Mayo de 2020
I have absolutely no idea what it is you are trying to do, because your code makes no sense.
So instead, I'll just show you how to compute arclength, using several methods. I'll pick a simple function - y=x^2. So what is the arclength of the curve (x,x^2), where x varies from 0 to 2?
First, we can compute that result in a symbolic form, and hope that the toolbox can handle it. The sqrt in there might be a problem.
syms x
y(x) = x^2;
int(sqrt(1 + diff(y).^2),x)
ans(x) =
asinh(2*x)/4 + x*(x^2 + 1/4)^(1/2)
int(sqrt(1 + diff(y).^2),x,[0,2])
ans =
log(17^(1/2) + 4)/4 + 17^(1/2)
So over the desired interval, we got a symbolic solution.
vpa(ans)
ans =
4.646783762432935873382616
Next, we can solve this using other schemes. Next, integral:
dy = @(x) 2*x;
integral(@(x) sqrt(1 + dy(x).^2),0,2)
ans =
4.64678376243294
Integral works quite well. Of course there I computed dy/dx myself.
Next, we can use trapz.
x = linspace(0,2,100);
yfun = @(x) x.^2;
sum(sqrt(diff(x).^2 + diff(yfun(x)).^2))
ans =
4.64675076773921
Trapz did quite well, considering that we only used 100 points along the curve.
Next, you could download my arclength utility from the file exchange. (I'll add a link in a minute.) Arclength actually passes a spline though those points, then computed the arclength along the spline interpolant itself. It forms an integral as needed internally. As you should expect the arclength computed using the integral of a spline interpolant should be more ccurate than what we get from trapz on the same set of points. But it is not as accurate as what we get from the sym solution or from integral.
arclength(x,yfun(x),'spline')
ans =
4.64678376533212
You can find arclength here for free download:
Next, we can use an ODE solver to solve the problem. A nice thing about the ODE solver is we also get the arclength at intermediate points along the curve. We would have gotten something similarly useful before, had we used cumtrapz instead of trapz.
dy = @(x) 2*x;
tfun = @(t,Y) sqrt(1 + dy(t).^2);
[tout,lenout] = ode45(tfun,[0,2],0);
lenout(end)
ans =
4.64678373566526
plot(tout,lenout)
grid on
So ODE45 did quite well too.
6 comentarios
haha mark
el 13 de Mayo de 2020
Can I ask you for help on this issue:https://www.mathworks.com/matlabcentral/answers/525051-how-to-integrate-discrete-values-over-a-known-x-y-coordinate-image?s_tid=prof_contriblnk
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!