用下面代码建了一个function文件 function f=Language(x,y,x0) syms t; if(length(

问题描述:

用下面代码建了一个function文件 function f=Language(x,y,x0) syms t; if(length(
用下面代码建了一个function文件
function f=Language(x,y,x0)
syms t;
if(length(x)=length(y))
n=length(x);
else
disp('x和y的维数不相等');
return;
end
f=0.0;
for(i=1:n)
l=y(i);
for(j=1:i-1)
l=l*(t-x(j))/(x(i)-x(j));
end;
for(j=i+1:n)
l=l*(t-x(j))/(x(i)-x(j));
end;
f=f+l;
simplify(f);
end
f0=subs(f,'t',x0);
然后在命令窗口输入如下三行
x=0:0.5:3;
>> y=[ 0 0.4794 0.8415 0.9975 0.9093 0.5985 0.1411];
>> [f,f0]=Language(x,y,1.6)
老是显示 Error:File:Language.m Line:3 Column:13
The expression to the left of the equals sign is not a valid target for an assignment.
请问各位大侠是哪里出错了!怎么修改?小弟新手!

function [f,f0]=Language(x,y,x0)%%你要输出f和f0,那你的函数的输出参数个数必须是2个
syms t;
if(length(x)==length(y))%%这里是判断,不能用=,要用==
n=length(x);
else
disp('x和y的维数不相等');
return;
end
f=0.0;
for(i=1:n)
l=y(i);
for(j=1:i-1)
l=l*(t-x(j))/(x(i)-x(j));
end;
for(j=i+1:n)
l=l*(t-x(j))/(x(i)-x(j));
end;
f=f+l;
simplify(f);
end
f0=subs(f,'t',x0);
%%其它的不用改
>>x=0:0.5:3;
y=[ 00.47940.84150.99750.90930.59850.1411];
[f,f0]=Language(x,y,1.6)
f =
-799/3125*t*(t-1)*(t-3/2)*(t-2)*(t-5/2)*(t-3)+561/500*t*(t-1/2)*(t-3/2)*(t-2)*(t-5/2)*(t-3)-133/75*t*(t-1/2)*(t-1)*(t-2)*(t-5/2)*(t-3)+3031/2500*t*(t-1/2)*(t-1)*(t-3/2)*(t-5/2)*(t-3)-399/1250*t*(t-1/2)*(t-1)*(t-3/2)*(t-2)*(t-3)+1411/112500*t*(t-1/2)*(t-1)*(t-3/2)*(t-2)*(t-5/2)
f0 = 0.9996
%%%直接调用运行,上面是运行结果.