Why does it not plot the function?

1 vue (au cours des 30 derniers jours)
gorilla3
gorilla3 le 13 Oct 2017
Commenté : Image Analyst le 13 Oct 2017
In the following series of functions, only the 1st one is being plotted. I don't understand why the others don't appear. Could you help?
function ode_metabolism
tau1= 2; %%1st time const of neural feedback
tau2= 4;
t=0:0.1:1000; % time scale
initial_xm = 0;
initial_dxmdt = 0;
[t,x]=ode45( @Fm, t, [initial_xm initial_dxmdt] );
%
% plot(t,x(:,1));
% xlabel('t'); ylabel('xm');
function dxmdt=Fm(t,x)
dxdt_1 = x(2);
dxdt_2 = (-tau2*x(2) - x(1)+eps*0.5)/tau1^2;
dxmdt=[dxdt_1; dxdt_2];
end
end
%%flow
function ode_q
q=12;
q_b=12.5;
G_q= 3; %%gain of flow based feedback mechanism
tau_q= 20; %%[s] time const of flow based feedback mechanism
t=0:0.1:100; % time scale
initial_xq = 0;
[t,xq]=ode45( @Fq, t, [initial_xq] );
plot(t,xq(:,1));
xlabel('t'); ylabel('xq');
function dxqdt=Fq(t,xq)
dxdt1 = (-xq +G_q* (q-q_b)/q_b)/tau_q;
dxqdt=[dxdt1];
end
end

Réponse acceptée

OCDER
OCDER le 13 Oct 2017
Modifié(e) : OCDER le 13 Oct 2017
Only the 1st function, ode_metabolism, is called since it is considered the main function.
Your ode_q function is viewed as a local function , which must be summoned by the main function, ode_metabolism, to be used.
To fix this, either have ode_metabolism call ode_q, OR make another main function that calls ode_metabolism and ode_q as local functions, like this:
function ode_main
ode_metabolism;
ode_q;
end
function ode_metabolism
...
end
function ode_q
...
end
  1 commentaire
gorilla3
gorilla3 le 13 Oct 2017
wonderful!

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 13 Oct 2017
You commented out the plot() call in ode_metabolism(), and the function ode_q() never gets called so the plot() in there never gets called either.
  2 commentaires
gorilla3
gorilla3 le 13 Oct 2017
yes, if I uncomment the metabolism() one it works. But the other plot never works and I don't know why cause it's the same code as above
Image Analyst
Image Analyst le 13 Oct 2017
It's because the ode_q() function is never called by your code, so how could that plot ever get called?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Objects 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!

Translated by