function f=fun(x); f=100*(x(2)-x(1)^2)^2+(1-x(1))^2; x=[1 2] fun(x)在MATLAB中运行后总出错?

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 00:49:06

function f=fun(x); f=100*(x(2)-x(1)^2)^2+(1-x(1))^2; x=[1 2] fun(x)在MATLAB中运行后总出错?
function f=fun(x); f=100*(x(2)-x(1)^2)^2+(1-x(1))^2; x=[1 2] fun(x)在MATLAB中运行后总出错?

function f=fun(x); f=100*(x(2)-x(1)^2)^2+(1-x(1))^2; x=[1 2] fun(x)在MATLAB中运行后总出错?
function f=chayou(x) % 在当前工作文件夹下保存为 chayou.m 文件
f=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
%%%%%%%%%%%%%%%%%%%%%%%%%
运行以下:
>> x=[1 2]
x =
1 2
>> chayou(x)
ans =
100
>>