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/06/27 03:24:59
![MATLAB:Input argument](/uploads/image/z/6837585-33-5.jpg?t=MATLAB%EF%BC%9AInput+argument+%22x%22+is+undefined.%E5%8E%9F%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8Bf02.mfunction+%5Bf%2CJ%5D+%3D+systemEqns%28x%29f%281%2C1%29+%3D+x%281%29%5E2%2Bx%282%29%5E2-4.0%3Bf%282%2C1%29+%3D+x%281%29%5E2%2F10%2Bx%282%29%5E2-1%3Bif+nargout+%3E+1%25+Jacobian+matrix+of+the+functionJ%281%2C1%29+%3D+2.0%2Ax%281%29%3BJ%281%2C2%29+%3D+2.0%2Ax%282%29%3BJ%282%2C1%29+%3D+x%281%29%2F5.0%3BJ%282)
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)';