MATLAB:Input argument "x" is undefined.原代码如下f02.mfunction [f,J] = systemEqns(x)f(1,1) = x(1)^2+x(2)^2-4.0;f(2,1) = x(1)^2/10+x(2)^2-1;if nargout > 1% Jacobian matrix of the functionJ(1,1) = 2.0*x(1);J(1,2) = 2.0*x(2);J(2,1) = x(1)/5.0;J(2
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 00:15:37
MATLAB:Input argument "x" is undefined.原代码如下f02.mfunction [f,J] = systemEqns(x)f(1,1) = x(1)^2+x(2)^2-4.0;f(2,1) = x(1)^2/10+x(2)^2-1;if nargout > 1% Jacobian matrix of the functionJ(1,1) = 2.0*x(1);J(1,2) = 2.0*x(2);J(2,1) = x(1)/5.0;J(2
MATLAB:Input argument "x" is undefined.
原代码如下
f02.m
function [f,J] = systemEqns(x)
f(1,1) = x(1)^2+x(2)^2-4.0;
f(2,1) = x(1)^2/10+x(2)^2-1;
if nargout > 1
% Jacobian matrix of the function
J(1,1) = 2.0*x(1);
J(1,2) = 2.0*x(2);
J(2,1) = x(1)/5.0;
J(2,2) = 2.0*x(2);
end
newton_syst.m
function c = newton_syst(fn,xinit,maxit,tolX,tolF)
%
% c = newton_syst('fn',xinit,maxit,tolX,tolF)
%
% Compute the root c such that f(c)=0 using Newton's method starting
% from xinit up to the point where | x_n - x_n+1 | < tolX or |f(x_n)| < tolF
% or the number of iteration exceeds maxit.
%
% 'fn' is the vector function contained in fn.m,a file in a directory
% of the MATLAB path.fn returns [f,G] with f the value of the function
% and G the Jacobian matrix of the function.
%
% initialize values
x = xinit';
[f,J] = feval(fn,x);
iteration = 0;
deltaX = 100.0; % || x_n - x_n+1 || is set to any large value to avoid stopping program
normF = norm(f,inf);
% display of iterates
disp('iteration |X_n - X_n-1| |f(X_n)|')
disp(sprintf('%d %16.14f %16.14f ',iteration,deltaX,normF))
% iterations
while (deltaX>tolX) & (normF>tolF) & (iteration> x=[1;1]
x =
1
1
>> newton_syst(f02,x,100,1e-10,1e-10)
newton方法解非线性方程组
为什么显示
Input argument "x" is undefined.
Error in ==> f02 at 2
f(1,1) = x(1)^2+x(2)^2-4.0;
MATLAB:Input argument "x" is undefined.原代码如下f02.mfunction [f,J] = systemEqns(x)f(1,1) = x(1)^2+x(2)^2-4.0;f(2,1) = x(1)^2/10+x(2)^2-1;if nargout > 1% Jacobian matrix of the functionJ(1,1) = 2.0*x(1);J(1,2) = 2.0*x(2);J(2,1) = x(1)/5.0;J(2
f02.m————这个改名为systemEqns,函数名最好和文件名一样
function [f,J] = systemEqns(x)
newton_syst(f02,x,100,1e-10,1e-10)
把f02改为@systemEqns 你传递的是函数,不是函数运算出来的值
改好后即可运行了,当然又会出现些其它错误,你自己继续处理好了.
________________________________
算了,我还是讲出来吧
xnew = x-J\f;
改为
xnew = x-(J\f)';