
matlab code least square method
조회 수: 6 (최근 30일)
이전 댓글 표시
x = 7.38, 5.86, 2.46, 6.66, 0.83, 6.26, 6.61, 7.29, 8.91, 9.82
y = 11.89, 2.01, 4.54, 7.26, 1.61, 3.99, 7.16, 11.17, 10.44, 1.97
y(x) = c1x + c2x^(2/3) + c3xsin(x)
Hi all , how can I find optimal parameters for c1, c2, c3 by applying least square algorithm.
댓글 수: 0
답변 (1개)
Image Analyst
2021년 9월 15일
You forgot to attach your code. I know it's obvious, but did you try the usual, easy formula? When you tried it, what went wrong? You forgot to give your error message.
x = [7.38, 5.86, 2.46, 6.66, 0.83, 6.26, 6.61, 7.29, 8.91, 9.82]
y = [11.89, 2.01, 4.54, 7.26, 1.61, 3.99, 7.16, 11.17, 10.44, 1.97 ]
plot(x, y, 'b.', 'MarkerSize', 20);
grid on;
% y(x) = c1x + c2x^(2/3) + c3xsin(x)
A = [x(:), x(:).^(2/3), x(:) .* sin(x(:))]
% y = A * c, so c = y/A
c = y(:) \ A
xFit = linspace(0, 10, 500);
yFit = c(1) * xFit + c(2) .* xFit .^ (2/3) + c(3) * xFit .* sin(xFit)
hold on;
plot(xFit, yFit, 'r-', 'LineWidth', 2);

댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!