Solving dependent functions using ODE45
1 view (last 30 days)
Show older comments
Hi All,
I am trying to solve a set of equations that are dependent on each other. dx_dt(1) is dependent on dx_dt(2). dx_dt(2) and dx_dt(3) are dependent on dx_dt(1). I have not been able to solve this. Any suggestions are greatly appreciated.
0 Comments
Accepted Answer
Star Strider
on 24 Jun 2016
The ode45 and other functions (choosing the appropriate solver is important) are able to solve such systems of differential equations relatively easily. Please post your code for your differential equation funciton, and original equations if necessary.
5 Comments
Star Strider
on 28 Jun 2016
The use of global variables is a remnant of earlier computer languages (like FORTRAN II that I learned programming with back in 1968) when that was the only way to pass variables and avoid some restrictions on subroutine (MATLAB function) usage. They are vestigial, and will eventually disappear. They are definitely to be avoided in MATLAB code.
One other problem you mentioned in a subsequent Question was that ‘dxdt(1)’ requires ‘dxdt(2)’. I would eliminate the double subscripts (that could be part of the problem), and instead insert a line defining ‘dxdt’ as a column vector from the outset:
...
iLoad = vC/Rload;
dxdt = zeros(7,1);
dxdt(1) = (x*(Vs - vC) + y*(-vj1 - Lp1*dxdt(2) - vC))/L; % diL/dt
...
and so for the others. I’m not certain that will solve your problem, since I didn’t run your code, but it should at least eliminate the problem you mentioned.
Torsten
on 29 Jun 2016
@Josh:
Take the first and the second equation (dxdt(1,:) = ... and
dxdt(2,:) = ...) and solve for dxdt(1) and dxdt(2) (2 linear equations in two unknowns).
Alternatively, use the mass-matrix option of the ODE integrators.
Best wishes
Torsten.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!