how can I create a polynom from some input variables that are output of another function?

5 visualizzazioni (ultimi 30 giorni)
I want to create and plot a polynom, whose coefficients are output from another function. Here is my code:
function c = interpolation(x, y)
n = length(x);
V = ones(n);
for j = 2:n
V(:,j) = x.*V(:,j-1);
end
c = V \ y;
disp(V)
for i = 0:n-1
fprintf('c%d= %.3f\n', i, c(i+1));
end
polynom(c)
function p = polynom(x)
n = length(x);
for l= 0:n-1
p = p + x^l;
end
disp(p)
end
end
the first function alone, works. and I get a value c which length is the length of the x vector.
but that values should discribe the polynom p(x) = c0*x^0 + c1*x^1 + ... + cN-1^(n-1)
How can I correct my code, so that I can display the polynom and use it to plot the function and it's points (xi,yi) so that I can see them on the plotted-function?

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by