Finding a parabolic function having two known points and curve shape

조회 수: 1 (최근 30일)
Hi,
I want to build a vector y that follows a parabolic function having two sets of points: (1,0.03) and (n,0), being n a variable that is defined earlier in my code. This means that the vector indexes go from 1 to n, being y(1) = 0.03 and y(n) = 0.
The curve must look like this (pardon my sloppy Paint skills):
I thought of creating a for loop, but don't know what to put inside it. Something like:
for i = 1:n
y(i) = %(insert polynomial function which I can't figure out here)
end
Any thoughts?
Thanks!

채택된 답변

Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 17일
p=polyfit([2-n, 1,n], [0, .03,0] ,2);
y=polyval(p,1:n)
  댓글 수: 3
Matt J
Matt J 2018년 10월 17일
편집: Matt J 2018년 10월 17일
We used polyfit to get the coefficients, p, of the parabola from the known points that it passes through.
Then we used polyval to evaluate the parabola on 1:n.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by