Error in ODE arguments in line 87
2 ビュー (過去 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!