在第一个方案link中,提供的解决方案非常出色并且确实有效。然而,我试图让它与另一个功能一起工作,我最终没有接近预期的东西。到目前为止我的代码:
yn = [-1.20449 -1.14398 -1.02273 -0.962285 -0.90203 -0.841474 -0.780881...
-0.720346 -0.659896 -0.579599 -0.539505 -0.478662 -0.418963 -0.35859...
-0.299039 -0.238886 -0.179108 -0.118999 -0.058841 -0.006249 -0.06189...
0.006332 0.04056 0.11813 0.1776723 0.238403 0.29827 0.358396...
0.418149 0.4786 0.478154 0.538114 0.53862 0.598954 0.659804...
0.720267 0.781026 0.8412 0.901548 0.962022 1.022567 1.083291...
1.143653];
xn = linspace(-22,22,43)';
yn = yn';
fn = fit(xn,yn,'poly1')
figure()
hold all
plot(fn,xn,yn)
yn_fit = f(xn);
error = yn - yn_fit;
figure()
plot(xn, error,'k')
我将不胜感激。