How to plot intermediate variables of a function used by ode45 solver:
Afficher commentaires plus anciens
Sir, I want to plot the intermediate variables say Te from a function that was used by ode45 solver .But i am not getting the response exactly. The time response of x is not constant(from the plot of (t,x(:,1))). But the The time response of Te seems to be constant with respect to time. The problem is ,in workspace i am not getting the array of Te values for all time instants.I am getting a single last value of Te say 4.5 (1x 1 Element) Workspace is having the last value of Te alone ie. at t=10 if tspan=[0 10]. But the vector of state variable x is coming in workspace.(say 1057x1) entries.(If x is time varying means Te should also vary with respect to time) . I tried giving Te as global variable also.But in vein.Please help me .
Main Pragram:
x0=0.1;
final_time=1;
[t,x]=ode45(@myfunc,[0,final_time],x0);% ODE Call
plot(t(:,1),x(:,1))% plotting the state varaible
Intervar=myfunc(t,x,'flag');
plot(t(:,1),Intervar)
main ends
Function :
function dv=myfunc(t,x)
H=1.0;
Te=2*x(1);% intermediate calculations/variables for my differential equations
%The Diffenrential Equation
dv=[(1/(H))*(Te)];
if nargin == 3
dv=Te; //Returns the intermediate variable Te
end
Réponses (2)
Azzi Abdelmalek
le 1 Août 2013
Modifié(e) : Azzi Abdelmalek
le 1 Août 2013
In your code Te represent 2*x, then why you don't just type
Te=2*x(:,2)
function dv = myfunc(t, x, flag)
H = 1.0;
Te = 2 * x(:, 1); % <-- Not "Te=2*x(1);"
dv = Te ./ H; % Btw, No additional square brackets
if nargin == 3
dv = Te;
end
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!