How to integrate a modified cfit funciton?

1 次查看(过去 30 天)
Please find the input variables c (sound speed m/s) and z (depth m) at end. Where sound speed is a function of depth c=c(z) I can get the fitted function f by
figure(1)
f=fit(z,c,'smoothingspline');
plot(f,z,c)
xlabel('Depth z ')
ylabel('Spund Speed C(z)')
I can do the integration from 30m to 50m for instance, which is
integrate(f,30,50);
But how can I modify the fitted function f then integrate like
integrate(sqrt(1./f^2-1/1800^2),30,50);
Is there any means to achieve this? Thank you!!!!!
c= [1532.35812332183;1532.09931142412;1531.55663714730;1531.13879204333;1527.17235792085;1524.06757234096;1520.77750440136;1500.98252643213;1494.68127723941;1490.39364113755;1487.89565341648;1487.62521870344;1495.01065240456;1503.30879683038;1503.53436491052];
z= [2.47551587249922;4.48813040298639;6.50074493347357;7.50705219871715;11.0039567548543;13.3491225832363;15.1491225832363;18.8991225832363;22.6491225832363;26.3991225832363;33.8991225832363;41.3991225832363;56.3991225832363;71.3991225832363;78.5991225832363];
  1 个评论
Matt J
Matt J 2017-12-24
编辑:Matt J 2017-12-24
Your post is now more readibly formatted thanks to this toolbar button:

请先登录,再进行评论。

采纳的回答

David Goodmanson
David Goodmanson 2017-12-27
Hi Tsuwei,
Here are two related methods. The first way just does a smoothing spline on the new function that you have defined:
c0 = 1800;
g = fit(z,(1./c.^2 - 1/c0^2),'smoothingspline');
I1 = integrate(g,50,30)
Because of the wonky syntax for the integrate function, the limits 30 and 50 have been reversed so that you get a positive result.
Since sound speed is the primary data, you may feel that it's better to fit sound speed with a smoothing spline rather than some derived quantity. In that case
I2 = integral(@(x) (1./f(x).^2 - 1/c0^2)', 30, 50)
works (note that a transpose sign ' is necessary). Since the original function c is so good, the two methods agree to within a couple of parts per million.
  1 个评论
Tsuwei Tan
Tsuwei Tan 2017-12-27
Thank you David! I used your second method and writes a function as output then I can integrate. I also use Simpson's method to do the integral with a very accurate result. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by