matlab函数的问题
有个关于函数定义跟函数调用的问题想请教一下大家function[x1x2]=equation_solve(a,b,c)delt=b*b-4*a*c;ifdelt<0'th...
有个关于函数定义跟函数调用的问题想请教一下大家
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 one answer!!!'
x1 = (-a+sqrt(delt))/2;
x2 = x1
ans = x1
else
'there is two answers!!!'
x1 = (-a+sqrt(delt))/2;
x2 = (-a-sqrt(delt))/2;
ans = [x1 x2]
end
这个是我自己定义的函数,存为equation_solve.m
[x1 x2] = equation_solve(1,2,4);
[x1 x2] = equation_solve(1,2,1);
[x1 x2] = equation_solve(1,2,-1);
这个是我调用定义的函数的脚本,但是运行以后显示
ans =
there is no answer!!!
出错 equation_solve (line 2)
delt = b*b - 4*a*c;
调用 "D:\Documents\MATLAB\equation_solve.m>equation_solve" 时,未对输出参数 "x1" (可能还包括其他参数)赋值。
出错 ex4_16 (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 one answer!!!'
x1 = (-a+sqrt(delt))/2;
x2 = x1
ans = x1
else
'there is two answers!!!'
x1 = (-a+sqrt(delt))/2;
x2 = (-a-sqrt(delt))/2;
ans = [x1 x2]
end
这个是我自己定义的函数,存为equation_solve.m
[x1 x2] = equation_solve(1,2,4);
[x1 x2] = equation_solve(1,2,1);
[x1 x2] = equation_solve(1,2,-1);
这个是我调用定义的函数的脚本,但是运行以后显示
ans =
there is no answer!!!
出错 equation_solve (line 2)
delt = b*b - 4*a*c;
调用 "D:\Documents\MATLAB\equation_solve.m>equation_solve" 时,未对输出参数 "x1" (可能还包括其他参数)赋值。
出错 ex4_16 (line 1)
[x1 x2] = equation_solve(1,2,4);
请问这个是什么意思,应该怎么修改呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询