I am solving with ODE45 diff equations system. How can i change a paramter in time for ODE45?
Show older comments
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...
Accepted Answer
More Answers (1)
installdisc
on 1 Jun 2016
0 votes
1 Comment
Star Strider
on 1 Jun 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.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!