I am solving with ODE45 diff equations system. How can i change a paramter in time for ODE45?
Mostra commenti meno recenti
hello,
I am solving with ODE45 diff equations system. How can i change a paramter in time for ODE45?
I am solving for z, 1,2,3,4-----and i got a paramter in this equations alfa......after a while i need a different alfa which changes with: alfa=-11782*log(t) + 106989; t is time......so i want to solve ode if my z(2) is a certain calue after that i need alfa t change.....how can i solve this HELP me pls?
% if (z(2)>0.32)
% alfa=23950;
% else
% % alfa=-11782*log(t) + 106989;
% end
tspan=[0 500];
[t,z]=ode45(@dYfdYdXdTgdTp,tspan,[y0 X0 Tg0 Tp0]);
alfa is in this @dYfdYdXdTgdTp function..
so i need something that after z(2) value reaching a certain value.....change my alfa in each step...whith an equation...
Risposta accettata
Più risposte (1)
installdisc
il 1 Giu 2016
0 voti
1 Commento
Star Strider
il 1 Giu 2016
You wouldn’t have to pass it from ode45 to your workspace. Just use the values of ‘z(:,2)’ and time to calculate in your workspace. The values of ‘z(:,2)’ and time should be the same, so just feed the two vectors to an anonymous function version of ‘alfa’ to calculate the value at corresponding values of the two variables.
For example:
alfa = @(z,t) 23950.*(z>0.32) - (11782*log(abs(t)+eps) + 106989).*(z<=0.32);
alfaa = alfa(z(:,2), t);
I would try that first.
Alternatively, you could write it to a .mat file from within your ODE function and then load it into your workspace later. The problem is that ode45 is an adaptive solver, so saving what you calculated from within the workspace of your ODE function to your workspace directly may not produce the results you want.
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!