matlab调用函数出错,函数本身运行可以 20
函数本身是这样,新建脚本输入这个调用函数就会出错[x1x2]=equation_solve(1,2,4)出错equation_solve(line2)delt=b*b-4...
函数本身是这样,新建脚本输入这个调用函数就会出错 [x1 x2] = equation_solve(1,2,4)出错 equation_solve (line 2)delt = b*b - 4*a*c;调用 "C:\Users\hasee\Documents\MATLAB\equation_solve.m>equation_solve" 时,未对输出参数 "x1" (可能还包括其他参数)赋值。出错 Untitled13 (line 1)[x1 x2] = equation_solve(1,2,4)求助求助
图片可能看不清,函数是很简单的,就这样
function [x1 x2] = equation_solve(a,b,c )
delt = b*b - 4*a*c;
if delt <0
'There is no answer!!!'
elseif delt == 0
'There is only one answer!'
x1 = (-b)/(2*a);
ans = x1
else
'There are two answers!'
x1 = (-b+sqrt(delt))/(2*a);
x2 = (-b-sqrt(delt))/(2*a);
ans = [x1 x2]
end 展开
图片可能看不清,函数是很简单的,就这样
function [x1 x2] = equation_solve(a,b,c )
delt = b*b - 4*a*c;
if delt <0
'There is no answer!!!'
elseif delt == 0
'There is only one answer!'
x1 = (-b)/(2*a);
ans = x1
else
'There are two answers!'
x1 = (-b+sqrt(delt))/(2*a);
x2 = (-b-sqrt(delt))/(2*a);
ans = [x1 x2]
end 展开
3个回答
展开全部
function [x1, x2] = equation_solve(a,b,c)
delt = b*b - 4*a*c;
if delt < 0
'There is no answer!!!'
else if delt == 0
'There is only one answer '
x1 = (-a+sqrt(delt))/2;
ans = x1
else
'There are two answers!!'
x1 = (-a+sqrt(delt))/2;
x2 = (-a-sqrt(delt))/2;
ans = [x1 x2]
end
end
原有这个文件没有问题,单独保存,相当于你自己设定了一种算法。然后你另建一个.M文件,写入代码如[x1 x2] = equation_solve(1,2,1);系统执行这行代码时将去调用上面那一段代码,然后输出结果。注意文件命名保存时要一致。
delt = b*b - 4*a*c;
if delt < 0
'There is no answer!!!'
else if delt == 0
'There is only one answer '
x1 = (-a+sqrt(delt))/2;
ans = x1
else
'There are two answers!!'
x1 = (-a+sqrt(delt))/2;
x2 = (-a-sqrt(delt))/2;
ans = [x1 x2]
end
end
原有这个文件没有问题,单独保存,相当于你自己设定了一种算法。然后你另建一个.M文件,写入代码如[x1 x2] = equation_solve(1,2,1);系统执行这行代码时将去调用上面那一段代码,然后输出结果。注意文件命名保存时要一致。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
matlab自学一本通p132页?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询