用matlab编写函数用matlab编写一个lagrange插值函数function [yy] = interp_lagrange(x,y,xx)n = prod(size(x)); [m2,n2] = size(xx);yy = zeros(m2,n2);for i = 1:nli = ones(m2,n2);for j = 1:nif j = i =i; li = li.*(xx-x(j))/(x(i)-x(j));endendyy =

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/02 18:30:20

用matlab编写函数用matlab编写一个lagrange插值函数function [yy] = interp_lagrange(x,y,xx)n = prod(size(x)); [m2,n2] = size(xx);yy = zeros(m2,n2);for i = 1:nli = ones(m2,n2);for j = 1:nif j = i =i; li = li.*(xx-x(j))/(x(i)-x(j));endendyy =
用matlab编写函数
用matlab编写一个lagrange插值函数
function [yy] = interp_lagrange(x,y,xx)
n = prod(size(x));
[m2,n2] = size(xx);
yy = zeros(m2,n2);
for i = 1:n
li = ones(m2,n2);
for j = 1:n
if j = i =i;
li = li.*(xx-x(j))/(x(i)-x(j));
end
end
yy = yy + li*y(i);
end
end
为什么输入后,x、y、yy总被电脑用棕色或者红色波浪线标记出来?调用函数的时候为什么提示
>> x=linspace(-1,0,10);
>> y=1/(1+25*x*x);
Error using *
Inner matrix dimensions must agree.
>> interp_lagrange(x,y,4)
Undefined function or variable 'y'.
到底我该怎么编写一个函数并且调用?

用matlab编写函数用matlab编写一个lagrange插值函数function [yy] = interp_lagrange(x,y,xx)n = prod(size(x)); [m2,n2] = size(xx);yy = zeros(m2,n2);for i = 1:nli = ones(m2,n2);for j = 1:nif j = i =i; li = li.*(xx-x(j))/(x(i)-x(j));endendyy =
y=1./(1+25*x.*x)