How to plot intermediate variables of a function used by ode45 solver:
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Azzi Abdelmalek
2013-8-1
编辑:Azzi Abdelmalek
2013-8-1
In your code Te represent 2*x, then why you don't just type
Te=2*x(:,2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!