Clear Filters
Clear Filters

How to solve and write system of differential equations?

7 views (last 30 days)
Hi, I am trying to solve this system through ODE45, and I tried two ways:
First:
function dxdt = rlcf(t,x)
I4 = (V - R1 * x(1)) / R4;
I3 = (V - R1 * x(1) - R2 * x(2)) / R3;
I5 = x(1) - x(2) - I4;
I6 = x(2) - I3;
dxdt(1,1) = (1/R1)*((V)-(I5/C1));
dxdt(2,1) = (1/R2)*((I5/C1)-(I6/C2));
I don't now how i write dVdt in this case... and my code enter in continuous loop.
Second:
function dxdt = rlcf(t,x)
dxdt(1,1) = (1/R1)*((V)-((x(1) - x(2) - ((V - R1 * x(1)) / R4))/C1));
dxdt(2,1) = (1/R2)*(((x(1) - x(2) - ((V - R1 * x(1)) / R4))/C1)-(((V - R1 * x(1) - R2 * x(2)) / R3)/C2));
In this case, the results in vector are 'NaN'.
How I write dVdt in this case?

Accepted Answer

Abraham Boayue
Abraham Boayue on 29 Mar 2018
Edited: Abraham Boayue on 29 Mar 2018
R1 = 500; R2 = 800; R3 = 1000; R4 = 200; C1 = 0.1;
C2 = 0.1; V = 180;
F = @(t,y)[y(1);
(y(1)/R1 -(y(2)-y(3)-V/R4-R1*y(2))/(R1*C1));
((y(2)-y(3)-V/R4-R1*y(2))/(R2*C1)-(y(3)-V/R3-R1*y(2)-R2*y(3))/(R2*C2))];
tspan = [1 2];
yin = [0 0 0];
[t,y]=ode45(F,tspan,yin);
plot(t,y(:,2),'linewidth',1.5,'color','b')
hold on
plot(t,y(:,3),'linewidth',1.5,'color','r')
grid;
a = title('I_1 and I_2');
legend('I_1','I_2');
set(a,'fontsize',14);
a = ylabel('y');
set(a,'Fontsize',14);
a = xlabel('t [0 1]');
set(a,'Fontsize',14);
  3 Comments
pml_28
pml_28 on 30 Mar 2018
Hi Abraham Boayue,
Thank you for your help! I'll check your code! On those days, I thought of this solution, I do not know if it's correct, I still have to check ... but look!
function dxdt = rlcf(t,x)
global R1 R2 R3 R4 C1 C2 V;
I4 = ((x(5) - R1 * x(1))) / R4;
I3 = ((x(5) - R1 * x(1) - R2 * x(3))) / R3;
I5 = x(1) - x(3) - I4;
I6 = x(2) - I3;
dxdt (1,1) = x(1);
dxdt (2,1) = (x(5) - (I5/C1)) / R1;
dxdt (3,1) = x(3);
dxdt (4,1) = ((I5/C1) - (I6/C2))/R2;
dxdt (5,1) = x(5);
dxdt (6,1) = R1*x(1) + (I5/C1);
  • dxdt (1,1) is I1
  • dxdt (2,1) is dI1/dt
  • dxdt (3,1) is I2
  • dxdt (4,1) is dI2/dt
  • dxdt (5,1) is V
  • dxdt (6,1) is dV/dt
I don't know this way is correct! What do you think? I do this, after you say for me, to separate V..
Abraham Boayue
Abraham Boayue on 30 Mar 2018
Edited: Abraham Boayue on 30 Mar 2018
You are welcome, you have two systems of ODE with three unknown quantities (I1, I2 and v ). It is not possible to solve for three variables given two equations. I made up the third equation to be able to get a solution. Your new function above is invalid because you haven't got that many ode in your problem. You actually have two 1st order equations which can not be further reduced. Check and see if you can obtain a third equaton involving dv/dt from the circuit diagram that you are working with. My solution is based on an assumption that dv/dt is as defined in the paper attached and may not be correct with respect to your problem. See this link on a similar problem : https://www.mathworks.com/matlabcentral/answers/391390-how-to-solve-nonlinear-coupled-dgl-second-order

Sign in to comment.

More Answers (2)

Abraham Boayue
Abraham Boayue on 28 Mar 2018
Edited: Abraham Boayue on 28 Mar 2018
ÌCheck your function dxdt, it has two inputs but uses othe variables that aren't defined. Some of these are V, R1, R2. t is an input but never used. Your use of I1 to I6 is quite good. Here is my recommendation
function [dx1 dx2] = rlcf(x1,x2, R1, R2, R3, R4, V)
  1 Comment
pml_28
pml_28 on 28 Mar 2018
Hi Abraham Boayue,
firstly thanks for the help!
the code above, is only my function. I am trying this:
global R1 R2 R3 R4 C1 C2 V;
R1 = 0.0001; R2 = 0.0001; R3 = 0.0001; R4 = 200; C1 = 0.0001;
C2 = 0.0001; V = 180;
x0=[0; 0];
tf=20;
deltat=1;
[tt,xt]=ode45('rlcf',[0:deltat:tf],x0);
the rlcf is my function dxdt...
but in this case I have other problem... In my function I write just V, but the correct is DvDt. How I write Dvdt in this case? Like this:
dxdt(1,1) = (1/R1)*(( dVdt)-(I5/C1));

Sign in to comment.


Abraham Boayue
Abraham Boayue on 28 Mar 2018
Edited: Abraham Boayue on 28 Mar 2018
Because the differential equation in line 1 is coupled, we will have to find a way to separate dv/dt from dI/dt.

Categories

Find more on Programming 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!