Using ODE data during solve

1 view (last 30 days)
Peter
Peter on 2 May 2013
Hi Guys,
I am trying to solve an ODE:
dX/dt + AX = Boundary Counds.
X is typically a 300x1 vector of displacement, velocity and force. A is 300x300.
My problem is that during the solve, I have various boundary conditions that rely on velocity and force at the previous time step. These relations are not linear (polynomial). In my function, thinking that as one time step is completed, the array X would be updated in the main program, I would then be able to call these values in the following iteration (ie X(previous_time_step)).
I dont know if I am doing this wrong or its not possible, because during the solve its saying that the size(X)=0.
Any suggestions on how I might be able to do this?
Hopefully this makes sense.
Cheers, Peter
  2 Comments
Peter
Peter on 3 May 2013
Hi All,
I actually managed to source a solution to this problem inhouse. If anyone else was after an answer:
Apparently MATLAB can handle non linear equations quite simply. You just add them in the function, not in matrix form. For instance, my solver was:
function dx=Package_1DNC_sub(t,x) . . . . dx=BC-AIC*x;
%This is the linear solution. I then wanted to add a non linear equation to the vector BC and couldnt figure out how to do it. I discovered we could add it to dx as a whole. Ie
for i=1... dx(i)=dx(i)+a*x(i)^4+b*x(i)^3.... etc end
Very handy and it works.
Hopefully this helps someone.
Cheers, Peter
Zhang lu
Zhang lu on 3 May 2013
Edited: Zhang lu on 3 May 2013
Hi. do you try difference mode to solve your ode?
dX/dt=(X(i+1,:)-X(i,:))*dt
and here dt can set a small time step.

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!