matlab中的函数调用问题

我在M-file下编写了一下程序 f.m function f=f(x,y); f=-y+x+1; 然后保存在work目录下 但是我调用时 我打[x,y]=euler('f',0,1,1) 他显示错误如下 Warning: EULER is obsolete and will be eliminated in future versions. Use SIM instead. > In E:\matlab\toolbox\simulink\simulink\euler.m at line 15 Warning: Unable to open model file 'f.mdl'. > In E:\matlab\toolbox\simulink\simulink\euler.m at line 63 ??? Error using ==> sim Unable to load block diagram 'f'. Error in ==> E:\matlab\toolbox\simulink\simulink\euler.m On line 63 ==> [t_cp2wksp,x_cp2wksp,y_cp2wksp] = sim(sys, time, simOptions, ut, varargin{:}); 还有我编写了fc.m function y=fc(x) y(1)=x(1)-0.7*sin(x(1))-0.2*cos(x(2)); y(2)=x(2)-0.7*cos(x(1))+0.2*sin(x(2)); y=[y(1) y(2)];保存在work下 然后输入x0=[0.5 0.5]; >> fsolve('fc',x0) 他显示错误如下Warning: Cannot determine from calling sequence whether to use new (2.0 or later) FSOLVE function or grandfathered FSOLVE function. Assuming new syntax; if call was grandfathered FSOLVE syntax, this may give unexpected results. To force new syntax and avoid warning, add options structure argument: x = fsolve(@sin,3,optimset('fsolve')); To force grandfathered syntax and avoid warning, add options array argument: x = fsolve(@sin,3,foptions); > In E:\matlab\toolbox\optim\fsolve.m (parse_call) at line 390 In E:\matlab\toolbox\optim\fsolve.m at line 102 ??? Error: File: E:\matlab\work\fc.m Line: 2 Column: 1 A function declaration cannot appear within a script M-file. Error in ==> E:\matlab\toolbox\optim\fsolve.m On line 162 ==> fuser = feval(funfcn{3},x,varargin{:}); 这是什么意思请帮忙!!!谢谢大家

第一个已将说明乐,euler过时了,在本版中背删掉。
第二个,你的函数明显没有end,加上去,不要y=[y(1)
y(2)],这是多余的。
运行得:
>>
x0=[0.5
0.5];
>>
fsolve('fc',x0)
Optimization
terminated:
first-order
optimality
is
less
than
options.TolFun.
ans
=
0.5265
0.5079
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-05-25
输入dna序列的长度n5
x=?a
x=?t
x=?c
x=?g
x=?a
1
4
2
3
3
2
4
1
5
4
???
undefined
function
or
variable
'x'.
error
in
==>
f3
at
5
f3=(abs(p)^3)/2-x^2+2/3
把f3保存到matlab的work目录下,在command
window里输入其他程序段,运行后出现上述错误,很明显,你定义的f3里的输入变量为p只有一个,而你的计算过程中却出现了x这个变量,按你的意思f3就应该有2个输入变量。你的函数编写是错误的。
相似回答
大家正在搜