Why does it not plot the function?

조회 수: 1 (최근 30일)
gorilla3
gorilla3 2017년 10월 13일
댓글: Image Analyst 2017년 10월 13일
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

채택된 답변

OCDER
OCDER 2017년 10월 13일
편집: OCDER 2017년 10월 13일
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개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by