필터 지우기
필터 지우기

How do I perform a sin^2 or a cos^2 fit for my data?

조회 수: 4 (최근 30일)
Akshay Arvind
Akshay Arvind 2024년 5월 23일
댓글: Star Strider 2024년 5월 23일
I have the following x data and y data:
x = [0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180]
y = [880,1200,1900,2700,3300,3600,3000,2100,1300,860,1200,1900,2700,3150,3300,2900,2100,1300,860]
How do I perform a cos^2 (x) or a sin^2 (x) fit for the above data?

채택된 답변

Star Strider
Star Strider 2024년 5월 23일
Perhaps this —
x = [0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180];
y = [880,1200,1900,2700,3300,3600,3000,2100,1300,860,1200,1900,2700,3150,3300,2900,2100,1300,860];
LvLocs = islocalmax(y, 'MinProminence',mean(y));
xlocs = x(LvLocs)
xlocs = 1x2
50 140
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
freq = 1/mean(diff(xlocs))
freq = 0.0111
[lb,ub] = bounds(y)
lb = 860
ub = 3600
fcn = @(b,x) b(1).*sin(2*pi*x*b(2)).^2 + b(3);
[B,fv] = fminsearch(@(b)norm(y - fcn(b,x)), rand(3,1))
B = 3x1
1.0e+03 * 2.5314 0.0006 0.9046
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fv = 371.2053
txt = sprintf('$f(x) = %.2f \\cdot sin(2 \\pi x %.3f)^2 %+.3f$', B)
txt = '$f(x) = 2531.45 \cdot sin(2 \pi x 0.595)^2 +904.574$'
figure
plot(x, y)
hold on
plot(x, fcn(B,x), '-r')
hold off
grid
xlabel('X')
ylabel('Y')
text(50, 3750, txt, 'Interpreter','LaTeX')
.
  댓글 수: 6
Akshay Arvind
Akshay Arvind 2024년 5월 23일
I see, thanks very much! I appreciate the help.
Star Strider
Star Strider 2024년 5월 23일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by