matlab symbolic equations into symbolic matrices and numerically solving

14 views (last 30 days)
I've got a simple example electrical circuit and i'm modelling it. First i generated all the equations for the physical elements and the next step would be to create the differential equations based on these. So lets say, i got these equations in matlab with the symbolic variables:
syms u1 u2 u3 u4 i1 i2 i3 i4 s1 R C I x1 x2 dx1 dx2
eqns = [u1==s1,u2==R*i2,u3==u1-u2-u4,u4==x2/C,i1==i3,i2==i3,i3==x1/I,i4==i3,dx1==u3,dx2==i4]
It can be solved easily by hand, you just need to replace all the variables till there is no i1,i2,... and u1,u2,... left in the 'solutions' for dx-es.
Here comes my first question, how could i create these two symbolic equations from the ones above?
  • dx1 = s1 - R/I * x1 - 1/C * x2
  • dx2 = 1/I * x1
After this the second step is to create two symbolic matrices from these two differential equations. One system matrix (A) and one for the sources (B) as you can see on the picture below.
The third and last step would be to render values to the parameters then evaluate the matrices' elements, which leaves me with two numerical matrices.
I've been trying to find a solution to this problem, by looking on forums and reading the matlab symbolic toolbox guide, however still haven't exactly found what i need. I used some functions like 'solve' , 'eliminate' ,... but couldn't make any progress and i'm not even sure if these functions can help me with my problem.
Generally i work with different sized models which means, it could contain much more state variables and sources.
Any help or guidance would be greatly appreciated about this three 'steps' like how to start / which functions to use / or a full solution would be the best.

Answers (1)

Stephan
Stephan on 1 May 2018
Edited: Stephan on 1 May 2018
Hi,
attached you find a .pdf-file exported from a live script where you find the first steps you need to understand how to do. It's only a incomplete part of your task. For example the second part with matrix B is not considered. But i think you'll see how you can solve this problem with symbolic toolbox.
I recommend doing this in a live script as shown in the attached file, because then you can see the equations in the usual mathematical notation and can, if necessary, manually recalculate for this example. Once you're done with the symbolic solution, you can put that into a Matlab functionhandle, for example, and do some numerical calculations.
A functionhandle is created with:
fun = matlabFunction(x)
Best regards
Stephan

Categories

Find more on Symbolic Math Toolbox 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!