Why does it not plot the function?

1 view (last 30 days)
gorilla3
gorilla3 on 13 Oct 2017
Commented: Image Analyst on 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

Accepted Answer

OCDER
OCDER on 13 Oct 2017
Edited: OCDER on 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

More Answers (1)

Image Analyst
Image Analyst on 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 Comments
gorilla3
gorilla3 on 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 on 13 Oct 2017
It's because the ode_q() function is never called by your code, so how could that plot ever get called?

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!