Error in ODE arguments in line 87
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone!
I'm trying to reed a .m funtion (with global variables) with the following script:
function [dY]=fun2(t,yfo)
for i=1:ng
for j=1:ng
if i~=j
aux2_pe=C_fal(i,j)*sin(yfo(i)-yfo(j))+D_fal(i,j)*cos(yfo(i)-yfo(j));
end
end
Pe_fal(i,1)=vg(i)^2*real(y_fal(i,i))+aux2_pe;
dy(i+ng)=(Pm(i)-Pe_fal(i,1))/M(i);
dy(i)=yfo(i+ng);
end
dY=[dy(1); dy(2); dy(3); dy(4); dy(5); dy(6)]
end
using the following codes for ODE23s:
yfo=[0.4677 0.4625 0.1171 0 0 0];
tspan=[0:0.002:0.198];
[tf,yf]=ode45('fun2',tspan,yfo);
and obtaining the following answer:
Undefined function or variable 'ng'.
Error in fun2 (line 5)for i=1:ng
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Untitled2 (line 246) [tf,yf]=ode45('fun2',tspan,yfo);
0 个评论
采纳的回答
Walter Roberson
2017-7-22
Global variables are only accessible in the workspaces where they are specifically declared with global.
Using global is not a good idea for this purpose. See http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!