请问下面Matlab定义函数中if nargin==0,x=0:.05:1;end有什么用?后面2个if作用是什么function[out1,out2]=hump(x)if nargin==0,x=0:.05:1;endy=1./((x-.3).^2+.1)+1./((x-.9).^2+.4)-6;if nargout==2out1=x;out2=y;elseout1=yend
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/29 19:01:45
![请问下面Matlab定义函数中if nargin==0,x=0:.05:1;end有什么用?后面2个if作用是什么function[out1,out2]=hump(x)if nargin==0,x=0:.05:1;endy=1./((x-.3).^2+.1)+1./((x-.9).^2+.4)-6;if nargout==2out1=x;out2=y;elseout1=yend](/uploads/image/z/10127182-22-2.jpg?t=%E8%AF%B7%E9%97%AE%E4%B8%8B%E9%9D%A2Matlab%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E4%B8%ADif+nargin%3D%3D0%2Cx%3D0%3A.05%3A1%3Bend%E6%9C%89%E4%BB%80%E4%B9%88%E7%94%A8%3F%E5%90%8E%E9%9D%A22%E4%B8%AAif%E4%BD%9C%E7%94%A8%E6%98%AF%E4%BB%80%E4%B9%88function%5Bout1%2Cout2%5D%3Dhump%28x%29if+nargin%3D%3D0%2Cx%3D0%3A.05%3A1%3Bendy%3D1.%2F%28%28x-.3%29.%5E2%2B.1%29%2B1.%2F%28%28x-.9%29.%5E2%2B.4%29-6%3Bif+nargout%3D%3D2out1%3Dx%3Bout2%3Dy%3Belseout1%3Dyend)
请问下面Matlab定义函数中if nargin==0,x=0:.05:1;end有什么用?后面2个if作用是什么function[out1,out2]=hump(x)if nargin==0,x=0:.05:1;endy=1./((x-.3).^2+.1)+1./((x-.9).^2+.4)-6;if nargout==2out1=x;out2=y;elseout1=yend
请问下面Matlab定义函数中if nargin==0,x=0:.05:1;end有什么用?后面2个if作用是什么
function[out1,out2]=hump(x)
if nargin==0,x=0:.05:1;end
y=1./((x-.3).^2+.1)+1./((x-.9).^2+.4)-6;
if nargout==2
out1=x;out2=y;
else
out1=y
end
请问下面Matlab定义函数中if nargin==0,x=0:.05:1;end有什么用?后面2个if作用是什么function[out1,out2]=hump(x)if nargin==0,x=0:.05:1;endy=1./((x-.3).^2+.1)+1./((x-.9).^2+.4)-6;if nargout==2out1=x;out2=y;elseout1=yend
nargin和nargout分别表示这个函数的输入和输出变量的个数.第一个if的意思:当输入变量个数为零时即没有输入,给输入变量x赋值x=0:.05:1.第二个if是:当输出变量个数为两个时,输入变量x的值赋给输出变量out1,计算的y值赋给输出变量out2,当输出变量为其他数时,只把计算的y值赋给out1.