how to solve a DAE system inside multiple class method with ode solver?

Good day,
For a school work, I am using object oriented programming in MatLab to simulate a system which consist of more than one object. Each object has it's own set of differential equations and algebraic equations. But in conjuction they are a system that I would like to solve with the ode solver for DAEs of MatLab.
I already simulate a single component, and has been analyzed using ode15s. for example, TypeA.DAEs is one of the components and depends on t and y (for this, the mass matrix is already defined for the opt input, and also the timestep). DAEs is a method inside the class which has the set of differential angebraic equations:
F=@(t,y) TypeA.DAEs(t,y);
[tsol,ysol]=ode15s(F,[0 timestep],y0,opt);
Like this, it works. However when I want to include a second component, TypeB.DAEs, I don't know how to include it. Also, this TypeB.DAEs also dependes on t and y and has defined the set of DAEs. I have ytrie dsomething like:
Fh1=@(t,y) TypeA.DAEs(t,y);
Fh2=@(t,y) TypeB.DAEs(t,y);
F={Fh1;Fh2};
[tsol,ysol]=ode15s(F,[0 timestep],y0,opt);
But I have errors that the ode solver does not accept this kind of input.
I would like to know if there is a way to do it and how to implement it.
If anyone knows or have already done this kind of thing and have a solution, I would very much appreciate it.
Thank you,

댓글 수: 6

Why do you want to simulate them together? Are they connected somehow?
Fh1=@(t,y) TypeA.DAEs(t,y);
Fh2=@(t,y) TypeB.DAEs(t,y);
F={Fh1;Fh2};
Can you show the objects?
Yes,
They are conected through one or more variables, that is, one of the "y"
The idea i s to simulate a system all together, which is compose of diferent components or "types".
I can do an example, so, for TypeA:
classdef TypeA<handle
methods
function out=DAEs(t,y,a,b)
out=zeros(2,1);
out(1)=(a+b)./2;
out(2)=a*y(1)+2*b*y(2);
end
end
end
Here are the diferential and algebraic equations for one type.
Then for the second one:
classdef TypeB<handle
methods
function out=DAEs(t,y,c,f)
out=zeros(3,1);
out(1)=c*(y(3)-f)-y(1);
out(2)=h(y(3))*y(4); % h is another function which depends on the value of y(3)
out(3)=y(3)+y(4);
end
end
end
So, the idea is to input the system of equations in TypeA.DAEs and TypeB.DAEs to the ode15s solver, with the respective mass matrix, and solve the system for a given timestep.
Thanks for the answer, hope you can help me.
I don't understand how they are connected
They are connected through the variable "y",
with y(1)
try this
f1 = @(t,y) [y(2);y(1)*y(2)];
f2 = @(t,y) [y(3);y(2);y(1)*y(3)];
F = @(t,y) [f1(t,y);f2(t,y)];
F(1,[1 2 3])
Super Thanks!
The ode accepted it :D
Thank you for your answer!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

릴리스

R2019b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by