How can I switch the differential equation according to the solution in ODE function ?

Hi. My differential equations are so complicated. So, I will try to simply explain my problem..
I am trying to solve differential equation using ODE45. For example,
/////
x0 = zeros(~~)
[t x] = ode45(@myfunction, tspan1, x0, options);
/////
and.. in the function
/////
function [DxDt] = myfunction(t,x)
DxDt = zeros(6,1)
a = matrix... and has to be switched according to (x) and (DxDt)
b = matrix... and has to be switched according to (x) and (DxDt)
DxDt = a*x + b
////
It is simple. But..
I need to switch the matrix a and b according to the solution of my differential equation. What I mean is that I should have two differential equation in the function, and the equations have to switched.
For example, I have 2 equations, E1 and E2 which are differential equation form.
if a > x+DxDt+10, I should use E1. however if a <= x+DxDt+10, I should use E2.
I can switch it now, but it is possible at initial time according to the initial value x0. I want to switch the E1 and E2 at every step time. I tried to use 'for' , 'if', and whatever I can, but I couldn't solve this problem.
I think this is because the values of x (solution of the differential equation) can not be obtained in the function. And the value of DxDt should not be returned to a and b in the function.
How can I switch the equations according to x and DxDt ? Thank you for reading.

Answers (0)

Tags

Asked:

on 3 Oct 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!