Error in ODE arguments in line 87
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 22 Juil 2017
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!