Matrix containing results of polynomial function
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I'm trying to create a matrix where some of the elements are the results of a polynomial function, the coefficients of which are taken from another matrix:
series_fit = [series(1,1) series(1,2) series(1,3) series(1,4) series(1,5) series(1,6);
(A(3,1)*series(1,1)^2)+(A(2,1)*series(1,1))+(A(1,1)*series(1,1))
(A(3,1)*series(1,2)^2)+(A(2,1)*series(1,2))+(A(1,1)*series(1,2))
(A(3,1)*series(1,3)^2)+(A(2,1)*series(1,3))+(A(1,1)*series(1,3))
(A(3,1)*series(1,4)^2)+(A(2,1)*series(1,4))+(A(1,1)*series(1,4))
(A(3,1)*series(1,5)^2)+(A(2,1)*series(1,5))+(A(1,1)*series(1,5))
(A(3,1)*series(1,6)^2)+(A(2,1)*series(1,6))+(A(1,1)*series(1,6))]
Matrix series is 2 x 6 containing x and y data pairs. Matrix A is 3 x 1 containing three polynomial coefficients. I'm trying to create a matrix I can pass to the PLOT() function, but I get the followinge error at the line above:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in tutorial_5a (line 38)
series_fit = [series(1,1) series(1,2) series(1,3) series(1,4) series(1,5) series(1,6);
I am very certain that this is not the best way to achieve what I'm trying to do, so any advice or guidance would be appreciated - I'm very muchfiguring this out as I go...
Thanks for any help :)
댓글 수: 0
답변 (1개)
William Rose
2022년 9월 5일
편집: William Rose
2022년 9월 5일
I assume you have 6 (x,y) pairs and a quadratic fit. Your equations show A(2,1) and A(1,1) both multiplying series(1,:). I suspect that is a mistake andthat the actual fitting equation is
yfit = a1 + a2*x + a3*x^2
Define the coefficients:
a=[-1,2,1];
Make some sample data,with random noise added:
x=1:6;
series=[x;a*[x.^0;x;x.^2]+randn(1,6)]
Computed the fitted values:
yfit=a*[x.^0;x;x.^2]
Plot results:
plot(series(1,:),series(2,:),'*r',x,yfit,'-r');
Try it.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!