【发布时间】:2015-11-08 16:57:03
【问题描述】:
我想将函数的输出用作构建多项式的函数的输入:
这是我的代码:
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
polynome(c);
function p = polynome(x)
n = length(x);
for l= 0:n-1
polynome = polynome * x^l;
end
end
单独的第一个功能有效。这意味着如果我从第 13 行开始注释到结束,我的代码就可以工作,并且我得到 c 值,其数量取决于开始时输入的 x 向量的长度。
我想使用该 c 值来构建这种形式的多项式:p(x) = c0 + c^1*x1 + c2^x2 + .... + c(n-1)^x(n-1) 并绘制该多项式,其中点以及 xi,yi 在开头通过 2 个向量作为函数插值的输入给出。
有人可以帮我吗?
【问题讨论】:
标签: matlab function input output polynomial-math