polynomial interpolation with lagrange form!!!

조회 수: 3 (최근 30일)
Anas Gharsa
Anas Gharsa 2022년 1월 25일
댓글: Anas Gharsa 2022년 1월 28일
I implemented a function of lagrange form and i want to use it to interpolate the function f(x) = sin(4x) for some datapoints!! i wrote the script for that but it always gives me error !!! can anyone help me with that !!!
this is my code
xval = 0:10;
pval = xval.^2;
xx = linspace(0,10);
yy = lagrange1(xx,xval,pval);
plot(xval,pval,'o',xx,yy,'.')
  댓글 수: 4
Torsten
Torsten 2022년 1월 25일
And the error message ?
Anas Gharsa
Anas Gharsa 2022년 1월 25일

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

채택된 답변

Alagu Sankar Esakkiappan
Alagu Sankar Esakkiappan 2022년 1월 28일
편집: Alagu Sankar Esakkiappan 2022년 1월 28일
Hello!
I see that you're trying to interpolate a polynomial but running into errors. I checked your code along with your function lagrange1 from your comments. It seems that you are running into an indexing error in the function lagrange1 on the line "Pval = Pval + Lval*f(i)". From what I observed using Breakpoint, you are trying to access f(12) when infact f only contains 11 elements to begin with.
Here are the Workspace values before the exact occurence of error:
If you try to evaluate the expression "Pval = Pval + Lval*f(i)" at this point ( based on values from above image ), you access f(12), thereby running into the error. I suggest for easier debugging, Try creating a Breakpoint on the line where error is caused in MATLAB. It'll give a more comprehensive view of the Codeflow and to narrow down exact occurence of error.
  댓글 수: 1
Anas Gharsa
Anas Gharsa 2022년 1월 28일
okay i will try that!! thank you so for the reply

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by