Finding a parabolic function having two known points and curve shape

1 visualización (últimos 30 días)
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!

Respuesta aceptada

Matt J
Matt J el 17 de Oct. de 2018
Editada: Matt J el 17 de Oct. de 2018
p=polyfit([2-n, 1,n], [0, .03,0] ,2);
y=polyval(p,1:n)
  3 comentarios
Matt J
Matt J el 17 de Oct. de 2018
Editada: Matt J el 17 de Oct. de 2018
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by