Creating a 3d plot of the solutions to an ODE as the time a switch condition activates varies
Mostra commenti meno recenti
Hi!

I am using a function with a subfunction to produce a graph of a piecewise smooth variable in an ODE. Smoothness is lost when t=t_1. Code for this is shown at the bottom of the question.
I'd like code to produce a 3d graph showing how different solutions look as t_1 varies. This would have the three axes t, t_1 and xa(:,1). Currently what I am stuck on is I am not sure how I could include t_1 as a a variable that is fed into ydot without creating confusing when ode45 calls it.
function L2_ode45
%a function to call ode45 and draw the graph
[t,xa] = ode45(@fu,[0 500],[0 0]);
plot(t,xa(:,1))
grid on
end
function ydot = fu(t,x)
%the function passed to ode45
%give values to parameters
t_1 = 200
k_a1 = 10^(-4);
k_a2 = 2*10^(-2);
C = 1;
R = 10;
k_d1 = 10^(-3);
k_d2 = 10^(-3);
%set up the switch
if t < t_1
z = C*(R-x(1)-x(2));
else
z = 0;
end
%set up the ROC function that will be output to ode45
ydot = [ k_a1*z-k_d1*x(1);...
k_a2*z-k_d2*x(2);];
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
